pion / dtls

DTLS 1.2 Server/Client implementation for Go
https://pion.ly/
MIT License
604 stars 158 forks source link

Race in setting LocalConnectionID #647

Closed Sean-Der closed 4 months ago

Sean-Der commented 4 months ago
==================
  WARNING: DATA RACE
  Read at 0x00c0001bfa08 by goroutine 2262:
    github.com/pion/dtls/v2.(*Conn).readAndBuffer()
        /home/runner/work/dtls/dtls/conn.go:707 +0x264
    github.com/pion/dtls/v2.(*Conn).handshake.func3()
        /home/runner/work/dtls/dtls/conn.go:1062 +0x1de

  Previous write at 0x00c0001bfa08 by goroutine 2261:
    github.com/pion/dtls/v2.flight4Generate()
        /home/runner/work/dtls/dtls/flight4handler.go:258 +0xccb
    github.com/pion/dtls/v2.(*handshakeFSM).prepare()
        /home/runner/work/dtls/dtls/handshaker.go:225 +0x412
    github.com/pion/dtls/v2.(*handshakeFSM).Run()
        /home/runner/work/dtls/dtls/handshaker.go:192 +0x8d7
    github.com/pion/dtls/v2.(*Conn).handshake.func2()
        /home/runner/work/dtls/dtls/conn.go:1043 +0x124

  Goroutine 2262 (running) created at:
    github.com/pion/dtls/v2.(*Conn).handshake()
        /home/runner/work/dtls/dtls/conn.go:1051 +0x8c4
    github.com/pion/dtls/v2.handshakeConn()
        /home/runner/work/dtls/dtls/conn.go:259 +0x1877
    github.com/pion/dtls/v2.ServerWithContext()
        /home/runner/work/dtls/dtls/conn.go:343 +0x1fd
    github.com/pion/dtls/v2.Server()
        /home/runner/work/dtls/dtls/conn.go:[295](https://github.com/pion/dtls/actions/runs/9910824373/job/27382124292#step:8:545) +0x126
    github.com/pion/dtls/v2.(*listener).Accept()
        /home/runner/work/dtls/dtls/listener.go:77 +0x135
    github.com/pion/dtls/v2/e2e.serverPion()
        /home/runner/work/dtls/dtls/e2e/e2e_test.go:251 +0x394
    github.com/pion/dtls/v2/e2e.(*comm).assert.gowrap2()
        /home/runner/work/dtls/dtls/e2e/e2e_test.go:134 +0x41

  Goroutine 2261 (running) created at:
    github.com/pion/dtls/v2.(*Conn).handshake()
        /home/runner/work/dtls/dtls/conn.go:1041 +0x753
    github.com/pion/dtls/v2.handshakeConn()
        /home/runner/work/dtls/dtls/conn.go:259 +0x1877
    github.com/pion/dtls/v2.ServerWithContext()
        /home/runner/work/dtls/dtls/conn.go:343 +0x1fd
    github.com/pion/dtls/v2.Server()
        /home/runner/work/dtls/dtls/conn.go:295 +0x126
    github.com/pion/dtls/v2.(*listener).Accept()
        /home/runner/work/dtls/dtls/listener.go:77 +0x135
    github.com/pion/dtls/v2/e2e.serverPion()
        /home/runner/work/dtls/dtls/e2e/e2e_test.go:251 +0x394
    github.com/pion/dtls/v2/e2e.(*comm).assert.gowrap2()
        /home/runner/work/dtls/dtls/e2e/e2e_test.go:134 +0x41
  ==================
      testing.go:1398: race detected during execution of test
Sean-Der commented 4 months ago

@hasheddan I will take a crack at this! Unless it is a super easy fix (missed lock somewhere)