Opened 16 years ago
Closed 16 years ago
#2381 closed bug (invalid)
[socket]: dup missing - which causes running out of file descriptors
Reported by: | emitrax | Owned by: | axeld |
---|---|---|---|
Priority: | normal | Milestone: | R1 |
Component: | Network & Internet/Stack | Version: | R1/pre-alpha1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
After running for a few minutes a simple multi threading application of mine, which basically open a tcp socket, dup it, pass it to a thread and then close it, I ran out of file descriptors. Too many open files is the error I get.
I looked at the code, and I found that normal calls that are made on file descriptors, like sockets are on Unix systems, are forwarded to the net module, which does not implement any dup function, which can be legally call on a socket in unix. So in my case, what happens is that the kernel dup the file descriptor, but never close it because the close on the same fd is forwared to the ipv4 module.
Change History (3)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
I'm actually aware of the file table with indexes slots, and dup just duplicate one of the slot, but I thought the socket was implemented totally different in Haiku, that's why I opened the ticket. Even because the same application runs fine on linux, but perhaps it has a greater limit for the max number of open descriptor now that you put it this way.
comment:3 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
You apparently misunderstood how file descriptors work. A file descriptor is an object representing an open file or socket. Each application has a file table with indexed slots (0 stdin, 1 stdout,...). Each slot can refer to a file descriptor. dup() and dup2() cause several slots to refer to the same file descriptor. A file descriptor (and thus the underlying file/socket) is closed when the last slot referring to it is closed. dup() and dup2() are handled by the kernel's FS layer. They just increment the open count of the file descriptor. The component responsible for the underlying open object doesn't need to know anything about such an operation.
Please check, that your code doesn't just leak sockets. If you're sure it doesn't, please attach a version as minimal as possible to the ticket.