You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 3423 Reporter: administrator Status: closed Resolution: fixed Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
Bug description
Sorry, I sent you my modified code instead of the original code for
"unix_accept" and "alloc_sockaddr". I've put the original source
back as it was in this forwarded copy of my original message.
The Mac OS X version of mldonkey has had a problem with orphaned file
descriptors. I was finally able to track down the source of the
problem and it has to do with the implementation of two of the unix
library routines "unix_accept" and "alloc_sockaddr". I've been
working the ocaml-3.08.0. Bascially the problem is that "unix_accept"
calls the unix routine "accept" which creates a file descriptor in
"retcode" (assuming no error). It then calls "alloc_sockaddr" and for
some reason, sometimes, the sa_family returned by unix "accept" does
not match any of the cases in "alloc_sockaddr". This causes
"unix_error" to be called in "alloc_sockaddr" which leave the file
descriptor open and there is no way in the user program to obtain and
close it.
unix_accept is in otherlibs/unix/accept.c and is:
CAMLprim value unix_accept(value sock)
{
int retcode;
value res;
value a;
union sock_addr_union addr;
socklen_param_type addr_len;
and "alloc_sockaddr" is in otherlibs/unix/socketaddr.c and is:
value alloc_sockaddr(union sock_addr_union * adr /in/,
socklen_param_type adr_len)
{
value res;
switch(adr->s_gen.sa_family) {
#ifndef _WIN32
case AF_UNIX:
{ value n = copy_string(adr->s_unix.sun_path);
Begin_root (n);
res = alloc_small(1, 0);
Field(res,0) = n;
End_roots();
break;
}
#endif
case AF_INET:
{ value a = alloc_inet_addr(&adr->s_inet.sin_addr);
Begin_root (a);
res = alloc_small(2, 1);
Field(res,0) = a;
Field(res,1) = Val_int(ntohs(adr->s_inet.sin_port));
End_roots();
break;
}
#ifdef HAS_IPV6
case AF_INET6:
{ value a = alloc_inet6_addr(&adr->s_inet6.sin6_addr);
Begin_root (a);
res = alloc_small(2, 1);
Field(res,0) = a;
Field(res,1) = Val_int(ntohs(adr->s_inet6.sin6_port));
End_roots();
break;
}
#endif
default:
unix_error(EAFNOSUPPORT, "", Nothing);
}
return res;
}
The "unix_accept" routine should close the open file descriptor in
"retcode" if "alloc_sockaddr" gets an error. I tested this by moving
the "unix_error" routine out of "unix_accept" and instead returned a
-1 to indicate an error. Then in each routine which called
"alloc_sockaddr" I tested the return value and called "unix_error" if
it was -1. Rebuilding mlnet (mldonkey) on Mac OS X with this change
eliminated the orphaned file descriptors. I do not know what value of
sa_family the unix "accept" command is returning to cause this error
or why it is returning a value that does not match your cases.
Since there appears to be no way for a user program that uses
"unix_accept" (ocaml Unix.accept) to obtain and close the file
descriptor opened by "unix_accept", I think that the library will have
to be changed to close "retcode" if alloc_sockaddr fails.
Thanks for your assistance.
Rand H. Childs
The text was updated successfully, but these errors were encountered:
working the ocaml-3.08.0. Bascially the problem is that
"unix_accept"
calls the unix routine "accept" which creates a file descriptor in
"retcode" (assuming no error). It then calls "alloc_sockaddr" and
for
some reason, sometimes, the sa_family returned by unix "accept" does
not match any of the cases in "alloc_sockaddr". This causes
"unix_error" to be called in "alloc_sockaddr" which leave the file
descriptor open and there is no way in the user program to obtain and
close it.
Thanks for the well-delimited bug report. This is now fixed in the CVS
version.
working the ocaml-3.08.0. Bascially the problem is that "unix_accept"
calls the unix routine "accept" which creates a file descriptor in
"retcode" (assuming no error). It then calls "alloc_sockaddr" and for
some reason, sometimes, the sa_family returned by unix "accept" does
not match any of the cases in "alloc_sockaddr". This causes
"unix_error" to be called in "alloc_sockaddr" which leave the file
descriptor open and there is no way in the user program to obtain and
close it.
Thanks for the well-delimited bug report. This is now fixed in the CVS
version.
Original bug ID: 3423
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Sorry, I sent you my modified code instead of the original code for
"unix_accept" and "alloc_sockaddr". I've put the original source
back as it was in this forwarded copy of my original message.
Rand
Begin forwarded message:
The text was updated successfully, but these errors were encountered: