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)
Feb 23 2024, 3:20 AM
Unknown Object (File)
Jan 13 2024, 11:40 AM
Unknown Object (File)
Dec 20 2023, 5:43 AM
Unknown Object (File)
Nov 10 2023, 6:19 AM
Unknown Object (File)
Oct 9 2023, 5:16 AM
Unknown Object (File)
Mar 21 2023, 11:53 AM
Unknown Object (File)
Mar 3 2023, 4:30 PM
Unknown Object (File)
Feb 21 2023, 6:46 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.