Fix a possible deadlock in TCP accepting

Each network thread holds an array of locks, indexed by a hash
of fd. When we accept a connection we hold a lock in accepting thread.
We then generate the thread number and lock bucket for the new
connection socket - if we hit the same thread and lock bucket as
accepting socket we get a deadlock. Avoid this by checking if we're
in the same thread/lock bucket and not locking in this case.

(cherry picked from commit 75815c15)
39 jobs for !1961 with 1046-deadlock-in-tcp-code-v9_14 in 11 minutes and 21 seconds (queued for 5 seconds)
detached
Status Job ID Name Coverage
  Precheck
passed 🐞:sid:amd64 #235934
amd64 linux

00:00:37

passed misc:sid:amd64 #235933
amd64 linux

00:00:17

 
  Build
passed asan:sid:amd64 #235945
amd64 linux

00:01:58

passed clang:stretch:amd64 #235946
amd64 linux

00:01:17

passed clang:stretch:i386 #235947
i386 linux

00:02:09

passed docs:sid:amd64 #235935
amd64 linux

00:00:45

passed gcc:bionic:amd64 #235944
amd64 linux

00:02:44

passed gcc:centos6:amd64 #235936
amd64 linux

00:02:16

passed gcc:centos7:amd64 #235937
amd64 linux

00:01:57

passed gcc:fedora29:amd64 #235942
amd64 linux

00:02:08

passed gcc:jessie:amd64 #235938
amd64 linux

00:01:09

passed gcc:sid:amd64 #235940
amd64 linux

00:01:51

passed gcc:sid:i386 #235941
i386 linux

00:01:33

passed gcc:stretch:amd64 #235939
amd64 linux

00:01:13

passed gcc:xenial:amd64 #235943
amd64 linux

00:01:40

passed pkcs11:sid:amd64 #235948
amd64 linux

00:01:44

 
  Test
passed system:asan:sid:amd64 #235967
amd64 linux

00:07:59

passed system:gcc:bionic:amd64 #235965
amd64 linux

00:06:47

passed system:gcc:centos6:amd64 #235949
amd64 linux

00:06:35

passed system:gcc:centos7:amd64 #235951
amd64 linux

00:06:27

passed system:gcc:fedora29:amd64 #235961
amd64 linux

00:07:04

passed system:gcc:jessie:amd64 #235953
amd64 linux

00:06:20

passed system:gcc:sid:amd64 #235957
amd64 linux

00:06:38

passed system:gcc:sid:i386 #235959
i386 linux

00:06:26

passed system:gcc:stretch:amd64 #235955
amd64 linux

00:06:24

passed system:gcc:xenial:amd64 #235963
amd64 linux

00:06:54

passed system:pkcs11:sid:amd64 #235970
amd64 linux

00:06:48

passed unit:asan:sid:amd64 #235968
amd64 linux

00:00:57

passed unit:clang:stretch:amd64 #235969
amd64 linux

00:00:45

passed unit:gcc:bionic:amd64 #235966
amd64 linux

00:00:44

passed unit:gcc:centos6:amd64 #235950
amd64 linux

00:00:46

passed unit:gcc:centos7:amd64 #235952
amd64 linux

00:01:01

passed unit:gcc:fedora29:amd64 #235962
amd64 linux

00:01:04

passed unit:gcc:jessie:amd64 #235954
amd64 linux

00:00:33

passed unit:gcc:sid:amd64 #235958
amd64 linux

00:00:48

passed unit:gcc:sid:i386 #235960
i386 linux

00:01:01

passed unit:gcc:stretch:amd64 #235956
amd64 linux

00:00:48

passed unit:gcc:xenial:amd64 #235964
amd64 linux

00:00:59

passed unit:pkcs11:sid:amd64 #235971
amd64 linux

00:00:48