Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
runtime: race in netpollinit vs netpoll #22606
I received a private report of a crash in netpoll, running go 1.8.3 on an old linux kernel:
This was at program startup during the program's first attempted net.Dial.
It looks to me like there is a race between netpollinit and netpoll. Specifically, netpollinit does:
If epollcreate1 fails (as I assume it might on an old kernel) then that first line is assigning a negative errno to epfd. Netpoll only checks that epfd != -1, which is why it passed -38 (-ENOSYS) to epollwait. Presumably netpollinit was about to overwrite the -38 with the result of epollcreate(1024), which was probably going to work, but it didn't get a chance.
More generally epfd is not itself an atomic variable. Instead there is an atomic netpollInited checked by func netpollinited. It looks like any call to netpoll should be guarded by an
1089 and 4242 need guards.
This is probably not reproducible in a test, but we should probably fix it anyway.