Skip to content

Data races / lack of synchronization #2156

@c4rlo

Description

@c4rlo

There are a few places in the code where (non-atomic) variables are getting accessed without proper synchronization.

Build flag -race helps bring some of these to light.

For example:

$ go build -gcflags="all=-N -l" -race
$ ./lf 2>err.log

Now inside lf, do:

%sleep inf
Ctrl-C
q

The resulting err.log shows racey accesses of, respectively, ui.wins, app.cmd, and app.ui.cmdPrefix:

==================
WARNING: DATA RACE
Write at 0x00c0001ca050 by main goroutine:
  main.(*ui).renew()
      .../ui.go:724 +0xb1
  main.(*callExpr).eval()
      .../eval.go:1279 +0x8893
  main.(*app).loop()
      .../app.go:491 +0x19a1
  main.run()
      .../client.go:66 +0xdf0
  main.main()
      .../main.go:370 +0x1810

Previous read at 0x00c0001ca050 by goroutine 27:
  main.(*nav).previewLoop()
      .../nav.go:730 +0x1ec
  main.(*app).loop.gowrap1()
      .../app.go:261 +0x50

Goroutine 27 (running) created at:
  main.(*app).loop()
      .../app.go:261 +0x1b6
  main.run()
      .../client.go:66 +0xdf0
  main.main()
      .../main.go:370 +0x1810
==================
==================
WARNING: DATA RACE
Write at 0x00c00054c020 by goroutine 39:
  main.(*app).runShell.func1()
      .../app.go:650 +0x357

Previous read at 0x00c00054c020 by main goroutine:
  main.(*callExpr).eval()
      .../eval.go:2010 +0x1a5d2
  main.(*app).loop()
      .../app.go:491 +0x19a1
  main.run()
      .../client.go:66 +0xdf0
  main.main()
      .../main.go:370 +0x1810

Goroutine 39 (running) created at:
  main.(*app).runShell()
      .../app.go:625 +0x21c6
  main.(*callExpr).eval()
      .../eval.go:1886 +0xf81d
  main.(*app).loop()
      .../app.go:491 +0x19a1
  main.run()
      .../client.go:66 +0xdf0
  main.main()
      .../main.go:370 +0x1810
==================
==================
WARNING: DATA RACE
Write at 0x00c0001ca0d8 by goroutine 39:
  main.(*app).runShell.func1()
      .../app.go:651 +0x3c4

Previous write at 0x00c0001ca0d8 by main goroutine:
  main.normal()
      .../eval.go:767 +0x22a
  main.(*callExpr).eval()
      .../eval.go:2018 +0x1a86b
  main.(*app).loop()
      .../app.go:491 +0x19a1
  main.run()
      .../client.go:66 +0xdf0
  main.main()
      .../main.go:370 +0x1810

Goroutine 39 (running) created at:
  main.(*app).runShell()
      .../app.go:625 +0x21c6
  main.(*callExpr).eval()
      .../eval.go:1886 +0xf81d
  main.(*app).loop()
      .../app.go:491 +0x19a1
  main.run()
      .../client.go:66 +0xdf0
  main.main()
      .../main.go:370 +0x1810
==================
Found 3 data race(s)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions