Linux code uses a netlink socket to be notified about network interface
changes. The code is a bit racy and for that reson it can happen that
the LinuxNetworkChange.OnDataAvailable handler is called after the
socket is destroyed (from a timer event) and socket stored in an
instance variable is already null. This is a race most probably
introduced by the new threadpool or TPL code as it started to happen in
several places (mostly BCL tests on Android, but it's *not* specific to
Android).
The workaround here serves as a quick band-aid to be able to move on,
but a more thorough review of the socket code will be required.
unsafe void OnDataAvailable (object sender, SocketAsyncEventArgs args)
{
+ if (nl_sock == null) // Recent changes in Mono cause MaybeCloseSocket to be called before OnDataAvailable
+ return;
EventType type;
- fixed (byte *ptr = args.Buffer) {
+ fixed (byte *ptr = args.Buffer) {
type = ReadEvents (nl_sock.Handle, new IntPtr (ptr), args.BytesTransferred, 8192);
}
nl_sock.ReceiveAsync (nl_args);