• Kirill Smelkov's avatar
    golang: Fix race in chan._trysend · eb8a1fef
    Kirill Smelkov authored
    For buffered channel _trysend, on success, was unlocking ch._mu too
    early - before accessing ch._dataq with ch._dataq.popleft().
    
    Without the fix, newly added test breaks as e.g.
    
        golang/golang_test.py::test_chan_buf_send_vs_tryrecv_race Exception in thread Thread-3:
        Traceback (most recent call last):
          File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
            self.run()
          File "/usr/lib/python2.7/threading.py", line 754, in run
            self.__target(*self.__args, **self.__kwargs)
          File "/home/kirr/src/tools/go/pygolang-master/golang/golang_test.py", line 256, in _
            assert (_, _rx) == (1, None)
        AssertionError: assert (0, 209) == (1, None)
          At index 0 diff: 0 != 1
          Full diff:
          - (0, 209)
          + (1, None)
    
        Exception in thread Thread-2:
        Traceback (most recent call last):
          File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
            self.run()
          File "/usr/lib/python2.7/threading.py", line 754, in run
            self.__target(*self.__args, **self.__kwargs)
          File "/home/kirr/src/tools/go/pygolang-master/golang/golang_test.py", line 243, in _
            ch.send(i)
          File "/home/kirr/src/tools/go/pygolang-master/golang/__init__.py", line 340, in send
            ok = self._trysend(obj)
          File "/home/kirr/src/tools/go/pygolang-master/golang/__init__.py", line 417, in _trysend
            rx = self._dataq.popleft()
        IndexError: pop from an empty deque
    eb8a1fef
__init__.py 20.5 KB