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

  • SEARCH
  • Home
  • 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 7916479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:49:29+00:00 2026-06-03T14:49:29+00:00

As mentioned elsewhere , this code has the potential for a race condition: //

  • 0

As mentioned elsewhere, this code has the potential for a race condition:

    // do stuff with client, catch exceptions
    if (client.State == CommunicationState.Faulted)
    {
        client.Abort();
    }
    else
    {
        // I hope nothing happened since I checked for a faulted state
        client.Close();
    }

… or does it?

As a State Machine, under what circumstances would a client go into a faulted state in-between attempts to check its state and subsequently close it? Even after several minutes/hours/days.

I tried the following simple-minded test, to rule out losing connection to the server:

  • put a break point at the if statement. I see client.State == opened. Step on.
  • Kill the WCF server process. Step on.
  • Client.Close() executes without a problem.

As a second test, rather than kill the server process, I waited for the ReceiveTimeout to elapse. Then I waited an extra minute. Then I stepped on to Client.Close(). No problem.

Can the client go into a faulted state without any input from me and, if not, is there really potential for a race condition?


EDIT: Perhaps this is too general, but I was looking for general guidance. The reason I asked this question is because I need to get some web developers to use WCF instead of obsolete web service technology. Ideally, I would like to be able to tell them that they can’t use using but they can use try-catch-finally as long as the finally checks for faulted state and aborts rather than closing (I think this approach is easy to understand and adopt – important, given that there is already quite a lot to learn when you start WCF).

Then I started thinking about the race condition issue and couldn’t think of an example where one might occur, given that the intent is to close the client, which you would not do if it was being used elsewhere (ie. shared between programs or threads in the current program.)

So, the question remains, is there potential for a race condition in this scenario and can anyone show me some code that demonstrates it?

  • 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. Editorial Team
    Editorial Team
    2026-06-03T14:49:32+00:00Added an answer on June 3, 2026 at 2:49 pm

    No satisfying answers, so the MSDN solution will have to do:

    try
    {
        ...
        client.Close();
    }
    catch (CommunicationException e)
    {
        ...
        client.Abort();
    }
    catch (TimeoutException e)
    {
        ...
        client.Abort();
    }
    catch (Exception e)
    {
        ...
        client.Abort();
        throw;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked many times here and elsewhere before as
My below mentioned code still submits form on special character in name field. Validation
I got below mentioned code for adding my application to Windows Firewall Exception list.
This question is a continuation of Malloc call crashing, but works elsewhere I tried
As mentioned below I have made changes to the code which looks like following
This link details on the various http client java implementations. I am looking for
The following VBA 6 in Excel 2000 code Resides in a form that has
Joel mentioned counting the number of set bits in a byte as a programming
Below mentioned is my XML, <?xml version=1.0 encoding=utf-8?> <soap:Envelopexmlns:soap=http://schemas.xmlsoap.org/soap/envelope/xmlns:xsi=http://www.w3.org/2001/XMLSchema-instancexmlns:xsd=http://www.w3.org/2001/XMLSchema> <soap:Body> <Response xmlns=http://tempuri.org/> <Result> <mp_response>
Joel Spolsky mentioned surfacing on the SO podcast. What does it mean? Is it

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.