Repository navigation
Description
This is primarily about named pipes but the problem may not be specific to it.
msbuild and Roslyn use named pipes to implement interprocess communication.
They randomly hang when running on FreeBSD. Also tests from System.IO.Pipes/tests/NamedPipeTests are failing on FreeBSD.
truss -o /tmp/trace.txt -f -d -H ../../../testhost/netcoreapp-FreeBSD-Debug-x64/dotnet xunit.console.netcore.exe System.IO.Pipes.Tests.dll -xml testResults.xml -notrait Benchmark=true -notrait category=nonnetcoreapptests -notrait category=nonfreebsdtests -notrait category=OuterLoop -notrait category=failing -showprogress -parallel none -method System.IO.Pipes.Tests.NamedPipeTest_Simple_ServerInOut_ClientOut.ManyConcurrentOperations
grep -e open -e kevent -e send -e connect -e accept -e recv /tmp/trace.txt
33324 100296: 1.389680761 connect(100,{ AF_UNIX "/tmp/CoreFxPipe_xzlvd23f.e50" },31) = 0 (0x0)
....
33324 101022: 1.491534421 sendmsg(0x64,0x7fffde7af760,0x0) = 512 (0x200)
33324 101022: 1.491692207 sendmsg(0x64,0x7fffde7af760,0x0) = 512 (0x200)
33324 101022: 1.492027215 sendmsg(0x64,0x7fffde7af760,0x0) ERR#35 'Resource temporarily unavailable'
33324 100288: 1.492083817 kevent(97,0x0,0,{ 103,EVFILT_READ,EV_CLEAR|EV_RECEIPT,0x0,0x2000,0x1 },32,0x0) = 1 (0x1)
33324 100288: 1.495819290 kevent(97,0x0,0,{ 100,EVFILT_READ,EV_CLEAR|EV_RECEIPT|EV_EOF,0x0,0x0,0x2 },32,0x0) = 1 (0x1)
33324 101022: 1.495844505 kevent(97,{ 100,EVFILT_READ,EV_ADD|EV_CLEAR|EV_RECEIPT,0x0,0x0,0x2 100,EVFILT_WRITE,EV_ADD|EV_CLEAR|EV_RECEIPT,0x0,0x0,0x2 },2,0x0,0,0x0) = 0 (0x0)
33324 100288: 31.737951300 kevent(97,0x0,0,{ 103,EVFILT_READ,EV_CLEAR|EV_RECEIPT|EV_EOF,0x0,0x0,0x1 },32,0x0) = 1 (0x1)
33324 100617: 1.588647366 recvmsg(0x67,0x7fffde9b12d0,0x0) = 512 (0x200)
33324 101060: 1.590081821 recvmsg(0x67,0x7fffddfac2d0,0x0) = 512 (0x200)
33324 101036: 1.592974978 recvmsg(0x67,0x7fffde5af2d0,0x0) = 512 (0x200)
33324 101285: 1.594100823 recvmsg(0x67,0x7fffdddab2d0,0x0) = 512 (0x200)
33324 101041: 1.594549209 recvmsg(0x67,0x7fffde1ad2d0,0x0) = 512 (0x200)
33324 101286: 1.595597996 recvmsg(0x67,0x7fffddbaa2d0,0x0) = 512 (0x200)
33324 101287: 1.595811634 recvmsg(0x67,0x7fffdd9a92d0,0x0) = 512 (0x200)
33324 100296: 1.595941461 recvmsg(0x67,0x7fffdebf32d0,0x0) = 512 (0x200)
33324 101038: 1.596414729 recvmsg(0x67,0x7fffde3ae2d0,0x0) = 512 (0x200)
33324 101036: 1.599841005 recvmsg(0x67,0x7fffde5af2d0,0x0) = 512 (0x200)
33324 101038: 1.601945788 recvmsg(0x67,0x7fffde3ae2d0,0x0) = 512 (0x200)
33324 100617: 1.605427075 recvmsg(0x67,0x7fffde9b12d0,0x0) = 512 (0x200)
33324 101038: 1.610128113 recvmsg(0x67,0x7fffde3ae2d0,0x0) = 512 (0x200)
33324 100617: 1.613307804 recvmsg(0x67,0x7fffde9b12d0,0x0) = 512 (0x200)
33324 101038: 1.616360676 recvmsg(0x67,0x7fffde3ae2d0,0x0) = 512 (0x200)
33324 101060: 1.617765858 recvmsg(0x67,0x7fffddfac2d0,0x0) = 512 (0x200)
33324 101285: 1.619783806 recvmsg(0x67,0x7fffdddab2d0,0x0) ERR#35 'Resource temporarily unavailable'
33324 100288: 31.737951300 kevent(97,0x0,0,{ 103,EVFILT_READ,EV_CLEAR|EV_RECEIPT|EV_EOF,0x0,0x0,0x1 },32,0x0) = 1 (0x1)
when send() fails we subscribe for readable and writable events. The reader will read data and empty socket buffers. But the writeable event will never come. Test will fail on timeout after 30s, msbuild just hangs forever.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
add reference to Issue: #30698
radovanovic commentedon Jun 27, 2018
Hi Tomas, can you attach entire output of truss (I didn't really check much of corefx code, but I did lot of unix domain socket programming lately, so maybe I can spot something)?
wfurt commentedon Jun 27, 2018
test is here for reference: https://github.com/dotnet/corefx/blob/5ee1494a4ff874c318cc27fe575dfaafbae646c2/src/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.Simple.cs#L722-L755
I think it may be worth of reconstructing the test in C (or other language) and see if that works.
trace.txt.gz
radovanovic commentedon Jun 27, 2018
To me it looks most likely that there is something broken with behavior of kevent EVFILT_READ on already half-closed socket - there was call
I would guess that order of last two is actually reversed (first subscribing from one thread and immediate return in second thread, possibly before
keventin first thread returned).I really can't see anything else suspicious. I will try to write simple test in C for that exact situation to see what will happen
wfurt commentedon Jun 27, 2018
yes, I think that can be ordering from different threads. Also note that msbuild and Roslyn do not shutdown the socket and they keep it bidirectional. I think key part is trying to register for both readable and writable event at the same time. If you look at my change, I simply do two kevent() calls and avoids the problem for some reason.
radovanovic commentedon Jun 27, 2018
Although probably doesn't make much sense either to check if socket that was closed from the same process has become readable :-)
wfurt commentedon Jun 27, 2018
As far as I know the readable subscription is there to pick up socket errors. I don't think you would get writable event of socket disconnects. If you have access to Mac it would be great to run tests there are well to see if kqueue on FreeBSD behaves different than osx.
radovanovic commentedon Jun 27, 2018
What I suspect is happening is that when you put both in one call, readable detects that there is eof and it returns but blocks other filters (I would also guess that if you first set writable filter and then readable filter you will get same broken behavior, but if you first register readable and then writable that would make it work).
Anyway simple test case in C will probably show if our guess is correct (I will try to write it tomorrow).
radovanovic commentedon Jun 27, 2018
Regarding kevent behavior OSX vs FreeBSD - it definitely behaves differently (I had to rewrite mono's version of FS watcher long time ago - it was for OSX and it didn't work at all on FreeBSD).
radovanovic commentedon Jun 29, 2018
Seems like bug in kevent implementation in FreeBSD, exactly same behavior from C (it alerts only about first filter if more than one passed in single kevent call). Your workaround with multiple calls to kevent seems to work no matter how you order it. Simple test is attached (expected result would be to see "XXX received EVFILT_WRITE" for any XXX, but instead for BothReadWrite only EVFILT_READ is received), We should file bug report
kevent_test.c.gz
use separate kevent() calls on FreeBSD for read and write event notif…
wfurt commentedon Jul 6, 2018
Thanks for the update @radovanovic. Do you know if this is specific to Unix Domain Sockets or is it general problem? For now, I submitted the workaround but it would be nice to have cmake detection at some point as suggested in linked PR.
Also if you have experience with fs watcher, please add notes to #14716 (or get it done :) )
radovanovic commentedon Jul 12, 2018
Sorry for being slow (too much work). I don't know, I did lot of socket programming but I didn't do lot of kqueue programming (in watcher I was using EVFILT_NODE, which was only one structure to add). I will fill that bug report since nobody came back on mailing list.
Regarding watcher I would really be glad to help, but at the moment you have all this very complicated (and I don't have access to either Windows or Linux machine), best I can do is look how you did Windows and Linux watcher and adjust my watcher to the same design, but somebody else will have to test it and try to build it.
wfurt commentedon Jul 12, 2018
full FreeBSD build is very close @radovanovic. With that, you will be able to compile code and run test on single FreeBSD system.
radovanovic commentedon Jul 12, 2018
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=229741 (although it shouldn't matter for implementation since you have already found workaround)
9 remaining items
dotnet-policy-service commentedon Dec 26, 2024
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This process is part of our issue cleanup automation.
dotnet-policy-service commentedon Jan 9, 2025
This issue will now be closed since it had been marked
no-recent-activitybut received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.