View Issue Details

IDProjectCategoryView StatusLast Update
0003926libmicrohttpdinternal event looppublic2021-09-02 17:54
Reporterdavidgf Assigned ToChristian Grothoff  
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 18:49

manager   ~0009512

Last edited: 2015-08-02 18: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 18: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 19: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 19:11

manager   ~0009515

Fix committed as SVN 36164.

Christian Grothoff

2021-09-02 17:54

manager   ~0018193

Fix committed to master branch.

Related Changesets

libmicrohttpd: master 58b30e7e

2015-08-02 21:11

Christian Grothoff


Details Diff
fix 0003926: ignore close() errors other than EBADF Affected Issues
0003926
mod - ChangeLog Diff File
mod - src/examples/demo.c Diff File
mod - src/examples/mhd2spdy_spdy.c Diff File
mod - src/include/microhttpd.h Diff File
mod - src/include/platform_interface.h Diff File
mod - src/microspdy/daemon.c Diff File
mod - src/microspdy/internal.h Diff File
mod - src/microspdy/session.c Diff File
mod - src/testcurl/https/test_https_time_out.c Diff File
mod - src/testcurl/https/test_tls_extensions.c Diff File
mod - src/testspdy/test_new_connection.c Diff File
mod - src/testspdy/test_notls.c Diff File
mod - src/testspdy/test_request_response.c Diff File

Issue History

Date Modified Username Field Change
2015-07-31 17:53 davidgf New Issue
2015-08-02 18:49 Christian Grothoff Note Added: 0009512
2015-08-02 18:49 Christian Grothoff Note Edited: 0009512
2015-08-02 18:58 davidgf Note Added: 0009513
2015-08-02 19:11 Christian Grothoff Note Added: 0009514
2015-08-02 19:11 Christian Grothoff Note Added: 0009515
2015-08-02 19:12 Christian Grothoff Status new => resolved
2015-08-02 19:12 Christian Grothoff Fixed in Version => 0.9.43
2015-08-02 19:12 Christian Grothoff Resolution open => fixed
2015-08-02 19:12 Christian Grothoff Assigned To => Christian Grothoff
2015-08-02 19:12 Christian Grothoff Product Version => Git master
2015-08-02 19:12 Christian Grothoff Target Version => 0.9.43
2015-09-16 11:00 Christian Grothoff Status resolved => closed
2021-09-02 17:54 Christian Grothoff Changeset attached => libmicrohttpd master 58b30e7e
2021-09-02 17:54 Christian Grothoff Note Added: 0018193
2024-01-21 13:24 Christian Grothoff Category libmicrohttpd internal select => internal event loop