Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 35829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:17:50+00:00 2026-05-10T14:17:50+00:00

Ok, I have a strange exception thrown from my code that’s been bothering me

  • 0

Ok, I have a strange exception thrown from my code that’s been bothering me for ages.

System.Net.Sockets.SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall    at System.Net.Sockets.Socket.Accept()    at System.Net.Sockets.TcpListener.AcceptTcpClient() 

MSDN isn’t terribly helpful on this : http://msdn.microsoft.com/en-us/library/ms741547(VS.85).aspx and I don’t even know how to begin troubleshooting this one. It’s only thrown 4 or 5 times a day, and never in our test environment. Only in production sites, and on ALL production sites.

I’ve found plenty of posts asking about this exception, but no actual definitive answers on what is causing it, and how to handle or prevent it.

The code runs in a separate background thread, the method starts :

public virtual void Startup()     {      TcpListener serverSocket= new TcpListener(new IPEndPoint(bindAddress, port));             serverSocket.Start(); 

then I run a loop putting all new connections as jobs in a separate thread pool. It gets more complicated because of the app architecture, but basically:

   while (( socket = serverSocket.AcceptTcpClient()) !=null) //Funny exception here     {          connectionHandler = new ConnectionHandler(socket, mappingStrategy);          pool.AddJob(connectionHandler);     }   } 

From there, the pool has it’s own threads that take care of each job in it’s own thread, separately.

My understanding is that AcceptTcpClient() is a blocking call, and that somehow winsock is telling the thread to stop blocking and continue execution.. but why? And what am I supposed to do? Just catch the exception and ignore it?


Well, I do think some other thread is closing the socket, but it’s certainly not from my code. What I would like to know is: is this socket closed by the connecting client (on the other side of the socket) or is it closed by my server. Because as it is at this moment, whenever this exception occurs, it shutsdown my listening port, effectively closing my service. If this is done from a remote location, then it’s a major problem.

Alternatively, could this be simply the IIS server shutting down my application, and thus cancelling all my background threads and blocking methods?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:17:51+00:00Added an answer on May 10, 2026 at 2:17 pm

    Is it possible that the serverSocket is being closed from another thread? That will cause this exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange requirement to ship an application without bundling .Net framework (to
I have a strange, sporadic issue. I have stored procedure that returns back 5
I have a strange problem with mod_rewrite, the rules that are relevant here are:
I'm trying to get the sample code from Mozilla that consumes a REST web
I have encountered a strange Invalid Packet Lenght (that is how the error is
I have strange problem with sharepoint and ajax functionality. We have an UpdatePanel placed
I have this strange call stack and I am stumped to understand why. It
I have a strange issue: I am using SPContext.Current.Web in a .aspx page, but
We have very strange problem, one of our applications is continually querying server by
I have this strange issue with my web app. You see, I'm using jQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.