On Windows, don't cancel I/O when disabling the device.
authorEtienne Dechamps <etienne@edechamps.fr>
Sat, 3 Dec 2016 23:13:46 +0000 (23:13 +0000)
committerEtienne Dechamps <etienne@edechamps.fr>
Sat, 3 Dec 2016 23:25:14 +0000 (23:25 +0000)
commitd21d97eaf5db9e848d8eee28784c4f54af85f43d
tree8b79c9e1b652fe4e97f96faf154275e4a4f3b017
parent1672dbd66b619f84cb86950298ad89df93e1dcba
On Windows, don't cancel I/O when disabling the device.

I have observed cases where disable_device() can get stuck on the
GetOverlappedResult() call, especially when the computer is waking up
from sleep. This is problematic when combined with DeviceStandby=yes:

    other_side (1.2.3.4 port 655) didn't respond to PING in 5 seconds
    Closing connection with other_side (1.2.3.4 port 655)
    Disabling Windows tap device
    <STUCK>

gdb reveals the following stack trace:

    #0  0x77c7dd3c in ?? ()
    #1  0x7482aad0 in KERNELBASE!GetOverlappedResult () from C:\WINDOWS\SysWoW64\KernelBase.dll
    #2  0x0043c343 in disable_device () at mingw/device.c:244
    #3  0x0040fcee in device_disable () at net_setup.c:759
    #4  0x00405bb5 in check_reachability () at graph.c:292
    #5  0x00405be2 in graph () at graph.c:301
    #6  0x004088db in terminate_connection (c=0x4dea5c0, report=true) at net.c:108
    #7  0x00408aed in timeout_handler (data=0x5af0c0 <pingtimer>) at net.c:168
    #8  0x00403af8 in get_time_remaining (diff=0x2a8fd64) at event.c:239
    #9  0x00403b6c in event_loop () at event.c:303
    #10 0x00409904 in main_loop () at net.c:461
    #11 0x00424a95 in main2 (argc=6, argv=0x2b42a60) at tincd.c:489
    #12 0x00424788 in main (argc=6, argv=0x2b42a60) at tincd.c:416

This is with TAP-Win32 9.0.0.9. I suspect driver bugs related to sleep.
In any case, this commit fixes the issue by cancelling I/O only when the
entire tinc process is being gracefully shut down, as opposed to every
time the device is disabled. Thankfully, the driver seems to be
perfectly fine with this code issuing TAP_IOCTL_SET_MEDIA_STATUS ioctls
while there are I/O operations inflight.
src/mingw/device.c