CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2006
    Posts
    3

    [RESOLVED] Select socket call crashes

    Hi,
    Can somebody help me in knowing in what cases select call can crash.

    If file descriptor being set in FD_SET is -1, the FD_SET crahses, i observed that .
    In case, select call has a Read FD list conatining a FD which is invalid i.e -1, the select call doesnt crash but returns an error -1.

    What can be other causes for select crash?

    Thanks

  2. #2
    Join Date
    Oct 2005
    Location
    Bangalore
    Posts
    1,051

    Re: Select socket call crashes

    Use GetLastError ()to find the exact cause of the error.
    - Sreehari
    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
    " Everybody is sent to Earth on a purpose. I am so Lagging behind that i won't die." – Calvin

  3. #3
    Join Date
    Dec 2006
    Posts
    3

    Re: Select socket call crashes

    GetLasterror() would be useful only if select returns without crashing.Program exits from select itself.
    The Program crashes at select call and its during load testing.So i need to know possible crash causes for select...

    To give an idea abt it...the backtrace looks like this:

    /lib/libc.so.6(__select+0x61)[0x41d79b91]

    /lib/libc.so.6[0x41ce1ae0]

    ./dcm(_ZN17CMH323Gk_RAS_Impl14ReadThreadFuncEPv+0x30)[0x87fe0aa]

    ./dcm(_Z22our_own_thread_routinePv+0x277)[0x884d939]

    /lib/libpthread.so.0[0x40017a4b]

    /lib/libc.so.6(__clone+0x57)[0x41d7f5b7]

    [0xb8bfec6c]

    [0x10c1c]

  4. #4
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Select socket call crashes

    That's no help.

    Post your code where you set up the fd_set's and then call select().

    Are you using the macros FD_ZERO and FD_SET, to clear and then add your socket descriptor to the fd_set?

    Which OS are your programming for?

    Mike

  5. #5
    Join Date
    Dec 2006
    Posts
    3

    Re: Select socket call crashes

    Find below the peice of code:

    Code:
     int l_fd_read = m_pUdp_device_read->GetSocket();
    
       while (!m_ReadThread->ShouldQuit ())
       {
          // Watch RAS listening socket to see when it has input.
          FD_ZERO (&l_fd_set);
    
          FD_SET (l_fd_read, &l_fd_set);
    
          // Wait up to 100 milliseconds.
          l_timeval.tv_sec = 0;
          l_timeval.tv_usec = 100000;
    
          int l_iRetval = select (l_fd_read + 1, &l_fd_set, 0, 0, &l_timeval);
    
          if (m_ReadThread->ShouldQuit ())
          {
             MLogError("GK_RAS_IF: ShouldQuit() from udp socket\n");
             break;
          }
    
          if (l_iRetval > 0)
          {
             if (FD_ISSET (l_fd_read, &l_fd_set))
             {
                int l_iBytesRead = m_pUdp_device_read->Read (l_caUdpReadBuffer,
                                                             sizeof (l_caUdpReadBuffer));
                if (l_iBytesRead > 0)
                {
                   // got something
                   ProcessIncomingMessage (l_caUdpReadBuffer, l_iBytesRead);
                }
                else if (l_iBytesRead ==  0)
                {
                   ;
                }
                else // l_iBytesRead < 0
                {
                   MLogError("GK_RAS_IF: failed to read from udp socket\n");
                   break;
                }
             }
          }
    See this code works fine, normally but crashes sometimes on running a call load test.

    My analysis:
    This select call is being done in a thread.
    There is a separate thread which closes the socket in FD list of select call sometimes and sets the FD = -1.
    But i have a tried a test program in which i set FD = -1, but select doesn't crash in that, just returns -1.
    Though FD_SET crashes..



    So cant figure out why select should crash???

    Any help is highly appreciated..
    Last edited by 2kaud; June 7th, 2018 at 05:31 AM.

  6. #6
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Select socket call crashes

    Is your application multithreaded?

    If so, then you need to synchronize access to the socket handle, so that the handle is not (for example) closed by one thread while it is still in use by another.

    Mike

  7. #7
    Join Date
    Jun 2018
    Posts
    2

    Re: Select socket call crashes

    I have the exact same issue.
    Calling select() crashes my program, no exception thrown, nothing.
    I have no multithreaded access to the socket.
    Did you ever solve this?
    Any ideas will be appreciated.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Select socket call crashes

    Wouldn't you like to post some code snippets?
    Victor Nijegorodov

  9. #9
    Join Date
    Jun 2018
    Posts
    2

    Re: Select socket call crashes

    Never mind. I feel like a total idiot.
    An asynchronous condition was causing my main() function to return, meaning my program was ending as normally as it gets.
    It just happens that it happened during the select()
    Everything's good now.

    Thanks nonetheless.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured