Page MenuHomeFreeBSD

Wakup applications with shutdown on listen sockets
ClosedPublic

Authored by jtl on Apr 9 2018, 4:18 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sep 28 2024, 4:15 AM
Unknown Object (File)
Sep 17 2024, 1:09 PM
Unknown Object (File)
Sep 16 2024, 2:09 AM
Unknown Object (File)
Sep 4 2024, 5:01 PM
Unknown Object (File)
Aug 31 2024, 2:02 AM
Unknown Object (File)
Aug 23 2024, 8:35 AM
Unknown Object (File)
Aug 18 2024, 11:14 PM
Unknown Object (File)
Aug 12 2024, 9:19 PM

Details

Summary

rS285910 attempted to make shutdown() be POSIX compliant by returning ENOTCONN when shutdown() is called on unconnected sockets. This change was slightly modified by rS316874, which returns ENOTCONN in the case of an unconnected datagram socket, but still runs the shutdown code for the socket. This specifically supports the case where the user-space code is using the shutdown() call to wakeup another thread blocked on the socket.

In PR 227259, a user is reporting that they have code which is using shutdown() to wakup another thread blocked on a stream listen socket. This code is failing, while it used to work on FreeBSD 10 and still works on Linux.

Without expressing an opinion on whether the underlying code *should* be written in this way, it seems reasonable to add another exception to support something users are actually doing and which used to work on FreeBSD 10 and still works on Linux. And, it seems like it should be acceptable to POSIX, as we still return ENOTCONN.

Test Plan

Run the code in the PR and make sure it works the way it used to work.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

No, this is not the right fix for head. However, if I change the spelling of SOLISTENING(so) to (so->so_options & SO_ACCEPTCON), then I think it is the right fix for 11.

Due to the changes in listening sockets in head, head will need a different fix.

This fix should work with HEAD.

Test results:

root@:/tmp # ./acc_test | grep "chk OK"
0:	socket(AF_INET, block)	... lskt  accept  shutdown  chk OK, ret code: 53 - Software caused connection abort
1:	socket(AF_INET, block)	... rskt  accept  shutdown  chk OK, ret code: 53 - Software caused connection abort
4:	socket(AF_INET, block)	... lskt  poll  shutdown  chk OK
5:	socket(AF_INET, block)	... rskt  poll  shutdown  chk OK
6:	socket(AF_INET, block)	... lskt  kqueue  shutdown  chk OK
7:	socket(AF_INET, block)	... rskt  kqueue  shutdown  chk OK
12:	socket(AF_INET, block)	... lskt  poll  close  chk OK
13:	socket(AF_INET, block)	... rskt  poll  close  chk OK
16:	socket(AF_INET, block)	... lskt  shutdown  accept  chk OK, ret code: 53 - Software caused connection abort
20:	socket(AF_INET, block)	... lskt  shutdown  poll  chk OK
22:	socket(AF_INET, block)	... lskt  shutdown  kqueue  chk OK
36:	socket(AF_INET, nblock)	... lskt  poll  shutdown  chk OK
37:	socket(AF_INET, nblock)	... rskt  poll  shutdown  chk OK
38:	socket(AF_INET, nblock)	... lskt  kqueue  shutdown  chk OK
39:	socket(AF_INET, nblock)	... rskt  kqueue  shutdown  chk OK
42:	socket(AF_INET, nblock)	... lskt  shutdown  poll  chk OK
43:	socket(AF_INET, nblock)	... lskt  shutdown  kqueue  chk OK

@glebius : Any progress on reviewing this? IIRC, you didn't like overloading the SS_ISDISCONNECTED flag to indicate listen sockets that were shutdown. Do you have an alternate proposal?

It is on my queue. The plan is to use so_error for this mark, instead of SS_ISDISCONNECTING.

This revision was not accepted when it landed; it landed in state Needs Review.Oct 3 2018, 5:40 PM
This revision was automatically updated to reflect the committed changes.