cossacklabs / acra

Database security suite. Database proxy with field-level encryption, search through encrypted data, SQL injections prevention, intrusion detection, honeypots. Supports client-side and proxy-side ("transparent") encryption. SQL, NoSQL.
https://www.cossacklabs.com/acra/
Apache License 2.0
1.36k stars 128 forks source link

Fix race conditions #488

Closed Lagovas closed 2 years ago

Lagovas commented 2 years ago

Met one failed test when run it locally:

CEF:0|cossacklabs|acra-server|0.91.0|100|Create listener|1|connection_string=tcp://localhost:10003 from_descriptor=false unixTime=1643996578.599 
2022-02-04T19:42:58+0200 - fork acra finished [pid=1384836]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x9e594d]

goroutine 57 [running]:
github.com/cossacklabs/acra/cmd/acra-server/common.(*SServer).addListener(...)
    /home/lagovas/development/acra/cmd/acra-server/common/listener.go:126
github.com/cossacklabs/acra/cmd/acra-server/common.(*SServer).StartCommands(0xc000296000, {0xeb6b40, 0xc00013b6c0})
    /home/lagovas/development/acra/cmd/acra-server/common/listener.go:459 +0x48d
github.com/cossacklabs/acra/cmd/acra-server/common.(*SServer).StartServer.func1()
    /home/lagovas/development/acra/cmd/acra-server/common/server.go:46 +0x65
created by github.com/cossacklabs/acra/cmd/acra-server/common.(*SServer).StartServer
    /home/lagovas/development/acra/cmd/acra-server/common/server.go:44 +0xd0
2022-02-04T19:42:59+0200 - terminate pid 1384836
2022-02-04T19:42:59+0200 - kill pid 1384836
2022-02-04T19:42:59+0200 - killed pid 1384836

After running acra-server with -race parameter compiler found some places with race conditions. Here they are fixed. No tests, because I don't know how to check it without manual checks with unit tests. And even running binary with this flag it only warns but don't stop execution (that we can detect by calls). IMHO, with this case we can leave it as is. Or discuss and plan how to run integration tests with compiled binaries with -race flag. But we should keep in mind that it decreases performance x2-x2.5 (measured it locally).

Checklist