LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-09-2008, 04:16 PM   #1
wkhoo
LQ Newbie
 
Registered: Apr 2008
Posts: 16

Rep: Reputation: 0
program exits with EBADF on a Socket read


the program I am running have no problem performing socket operations when it first started up. After running the program and be doing task for prolong time, the program exits.
using Strace it state that the program quits on EBADF, I can see why its getting a EBADF. why its doing a close on a incomplete read (recvfrom)? I am using Linux Datagram.

Quote:
534 read(11, <unfinished ...>
540 close(11) = 0
540 SYS_292(0xa, 0x1e284, 0x1000, 0, 0x1e20a) = 12
540 SYS_292(0xa, 0x1e284, 0x1000, 0, 0x1e20a <unfinished ...>
534 <... read resumed> 0x265d0, 2048) = -1 EBADF (Bad file descriptor)
534 io_submit(0x1, 0x1, 0x401107dc <unfinished ...>

there isn't a core dump file that I can use GDB to bebug.
I did run valgrind to check for memory problems.

what are the suggested ways to prevent this from happening?

Last edited by wkhoo; 12-09-2008 at 04:44 PM.
 
Old 12-09-2008, 09:09 PM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
It is not necessarily possible to prevent it from happening - that depends on what exactly causes the close.

If you want a coredump, you need to specify the maximum size in the shell before running the program:
ulimit -c 1k_byte_blocks_reserved_for_coredump
 
Old 12-09-2008, 10:01 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You don't need a coredump if you use GDB to debug it from the start.
ta0kira
 
Old 12-10-2008, 08:03 AM   #4
wkhoo
LQ Newbie
 
Registered: Apr 2008
Posts: 16

Original Poster
Rep: Reputation: 0
I did set ulimit -c unlimited and I did not get any core dump.
I am running the code in a embedded system. Its is possible to do a remote GDB to debug the issue. problem is this issue is 90% reproducible.

anyone has ideas why its doing a close on a unfinished read?
 
Old 12-10-2008, 03:16 PM   #5
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
1. why 'unlimited' rather than an actual number?

2. if the system is set up for remote debugging then you can use remote debugging; there are some extra things to do though, it doesn't happen magically.

3. no idea; the information you provided really doesn't tell us much so you'll have to trace through the program and look at what things might cause the failure and test which case did cause the failure. In general, when dealing with sockets you can expect them to close at any time; 'SIGPIPE' can also be generated. It is even possible for a memory management problem in your code to cause the failure. It really is up to you to debug this because it is not a problem which can be resolved with a fixed set of instructions.
 
Old 12-11-2008, 04:35 AM   #6
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by pinniped View Post
...

3. no idea; the information you provided really doesn't tell us much so you'll have to trace through the program and look at what things might cause the failure and test which case did cause the failure. In general, when dealing with sockets you can expect them to close at any time; 'SIGPIPE' can also be generated. It is even possible for a memory management problem in your code to cause the failure. It really is up to you to debug this because it is not a problem which can be resolved with a fixed set of instructions.
+1

OP: Please list the code around, and including, the area where the recv() is being used. Perhaps it is possible that you are somehow smashing the stack where your file descriptor resides as you are reading data.
 
Old 12-11-2008, 04:31 PM   #7
wkhoo
LQ Newbie
 
Registered: Apr 2008
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pinniped View Post
1. why 'unlimited' rather than an actual number?

2. if the system is set up for remote debugging then you can use remote debugging; there are some extra things to do though, it doesn't happen magically.

3. no idea; the information you provided really doesn't tell us much so you'll have to trace through the program and look at what things might cause the failure and test which case did cause the failure. In general, when dealing with sockets you can expect them to close at any time; 'SIGPIPE' can also be generated. It is even possible for a memory management problem in your code to cause the failure. It really is up to you to debug this because it is not a problem which can be resolved with a fixed set of instructions.

1) don't know what number to put, so had it unlimited. unlimited is a bad thing in linux?

2) I understand that perfectly, no hoping any thing to happen magically in this world. Not asking it to happen magically too! ^^;

3) Problem is I don't know why it happen. if a SIGPIPE was to happen will STRACE capture it? I am not aware that sockets are unreliable and I have expect it to close anytime unexpectly. I will take care of it. I am not asking guru here to help me debug the problem or magically resolve my issue. I should have phrase it better, I am asking if ppl experience similar incident what approach is taken to resolve it.
yes it might be possible its a memory issue. I will spend time adding self ptr to ensure no memory are trash.

thanx for all the tips.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
!! Problem !! Minimizing ANY window EXITS the Program / Browser window NOoBuntuLinux Linux - Newbie 6 11-20-2008 02:32 PM
read from socket error, what does it mean? gklive Linux - Networking 1 09-11-2008 09:01 AM
cannot read data at server socket, though client socket sends it jacques83 Linux - Networking 0 11-15-2005 01:58 PM
C++ Socket: How to read a long maldini1010 Programming 3 02-25-2005 03:56 PM
read socket adoyee Programming 3 02-26-2004 06:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration