View Issue Details

IDProjectCategoryView StatusLast Update
0003926libmicrohttpdinternal event looppublic2021-09-02 15:54
Reporterdavidgf Assigned ToChristian Grothoff Due Date
PriorityhighSeveritycrashReproducibilityrandom
Status closedResolutionfixed 
PlatformLinux 3.XOSLinuxOS Version3.X
Product VersionGit master 
Target Version0.9.43Fixed in Version0.9.43 
Summary0003926: Checking result of close() in a wrong way?
DescriptionIt seems that daemon.c checks whether the result from close() is zero. In case it's non zero it may trigger a panic.
POSIX says that we can get EINTR, therefore IMHO we should not check close() result, just makes no sense.
Steps To ReproduceUnder heavy load, multithreaded program I get random crashes at "panic close failed".
TagsNo tags attached.

Activities

Christian Grothoff

2015-08-02 16:49

manager   ~0009512

Last edited: 2015-08-02 16:49

Well, POSIX is (or at least used-to-be) *wrong* on close in the first place. Terrible choice of semantics. (See also http://lwn.net/Articles/576478/). Now, it seems (!) from this article that it may be safe to continue on GNU/Linux if errno is EINTR or (more correct) EINPROGRESS, but unsafe on other "POSIX" platforms (possible leak of a file-descriptor). Now, this is a kernel/libc issue, as libc should probably just return 0 instead of EINPROGRESS (see also https://news.ycombinator.com/item?id=3363819).

So on GNU/Linux, where the FD is *always* closed, POSIX says that errno should be EINPROGRESS (or the return value just zero). musl now does this (http://ewontfix.com/4/), so we get additional fun with the "correct" action depending on the kernel and the libc. Party.

davidgf

2015-08-02 16:58

reporter   ~0009513

So in non-linux platforms, what happens if we get EINTR/EINPROGRESS? Should we re-issue the syscall? Cause that would be very tricky

Christian Grothoff

2015-08-02 17:11

manager   ~0009514

My reading is that only HP-UNIX has the non-closing semantics, and in that case may have undefined semantics (as in, it may be closed -- or not). So I'm going with screw HP-UNIX, never retry, ignore all errors except EBADF.

Christian Grothoff

2015-08-02 17:11

manager   ~0009515

Fix committed as SVN 36164.

Christian Grothoff

2021-09-02 15:54

manager   ~0018193

Fix committed to master branch.

Issue History

Date ModifiedUsernameFieldChange
2015-07-31 15:53davidgfNew Issue
2015-08-02 16:49Christian GrothoffNote Added: 0009512
2015-08-02 16:49Christian GrothoffNote Edited: 0009512
2015-08-02 16:58davidgfNote Added: 0009513
2015-08-02 17:11Christian GrothoffNote Added: 0009514
2015-08-02 17:11Christian GrothoffNote Added: 0009515
2015-08-02 17:12Christian GrothoffStatusnew => resolved
2015-08-02 17:12Christian GrothoffFixed in Version => 0.9.43
2015-08-02 17:12Christian GrothoffResolutionopen => fixed
2015-08-02 17:12Christian GrothoffAssigned To => Christian Grothoff
2015-08-02 17:12Christian GrothoffProduct Version => Git master
2015-08-02 17:12Christian GrothoffTarget Version => 0.9.43
2015-09-16 09:00Christian GrothoffStatusresolved => closed
2021-09-02 15:54Christian Grothoff
2021-09-02 15:54Christian GrothoffNote Added: 0018193
2024-01-21 12:24Christian GrothoffCategorylibmicrohttpd internal select => internal event loop