startGoRoutine will execute the closed function as a go routine, so passing copyBytes(msg) as the argument caused a race. The copy needs to be done before startGoRoutine, as it was before being changed in https://github.com/nats-io/nats-server/pull/2925 Here is the race observed: ``` ================== WARNING: DATA RACE Write at 0x00c0001dd930 by goroutine 367: runtime.racewriterange() <autogenerated>:1 +0x29 internal/poll.ignoringEINTRIO() /home/travis/.gimme/versions/go1.17.8.linux.amd64/src/internal/poll/fd_unix.go:582 +0x454 internal/poll.(*FD).Read() /home/travis/.gimme/versions/go1.17.8.linux.amd64/src/internal/poll/fd_unix.go:163 +0x26 net.(*netFD).Read() /home/travis/.gimme/versions/go1.17.8.linux.amd64/src/net/fd_posix.go:56 +0x50 net.(*conn).Read() /home/travis/.gimme/versions/go1.17.8.linux.amd64/src/net/net.go:183 +0xb0 net.(*TCPConn).Read() <autogenerated>:1 +0x64 github.com/nats-io/nats-server/v2/server.(*client).readLoop() /home/travis/gopath/src/github.com/nats-io/nats-server/server/client.go:1188 +0x8f7 github.com/nats-io/nats-server/v2/server.(*Server).createLeafNode.func1() /home/travis/gopath/src/github.com/nats-io/nats-server/server/leafnode.go:904 +0x5d Previous read at 0x00c0001dd930 by goroutine 93: runtime.slicecopy() /home/travis/.gimme/versions/go1.17.8.linux.amd64/src/runtime/slice.go:284 +0x0 github.com/nats-io/nats-server/v2/server.copyBytes() /home/travis/gopath/src/github.com/nats-io/nats-server/server/util.go:282 +0x10b github.com/nats-io/nats-server/v2/server.(*Server).jsStreamListRequest.func1() /home/travis/gopath/src/github.com/nats-io/nats-server/server/jetstream_api.go:1613 +0x26 Goroutine 367 (running) created at: github.com/nats-io/nats-server/v2/server.(*Server).startGoRoutine() /home/travis/gopath/src/github.com/nats-io/nats-server/server/server.go:3017 +0x86 github.com/nats-io/nats-server/v2/server.(*Server).createLeafNode() /home/travis/gopath/src/github.com/nats-io/nats-server/server/leafnode.go:904 +0x1b08 github.com/nats-io/nats-server/v2/server.(*Server).startLeafNodeAcceptLoop.func1() /home/travis/gopath/src/github.com/nats-io/nats-server/server/leafnode.go:604 +0x4b github.com/nats-io/nats-server/v2/server.(*Server).acceptConnections.func1() /home/travis/gopath/src/github.com/nats-io/nats-server/server/server.go:2122 +0x58 Goroutine 93 (running) created at: github.com/nats-io/nats-server/v2/server.(*Server).startGoRoutine() /home/travis/gopath/src/github.com/nats-io/nats-server/server/server.go:3017 +0x86 github.com/nats-io/nats-server/v2/server.(*Server).jsStreamListRequest() /home/travis/gopath/src/github.com/nats-io/nats-server/server/jetstream_api.go:1613 +0xbf1 github.com/nats-io/nats-server/v2/server.(*Server).jsStreamListRequest-fm() /home/travis/gopath/src/github.com/nats-io/nats-server/server/jetstream_api.go:1554 +0xcc github.com/nats-io/nats-server/v2/server.(*jetStream).apiDispatch() /home/travis/gopath/src/github.com/nats-io/nats-server/server/jetstream_api.go:680 +0xcf0 github.com/nats-io/nats-server/v2/server.(*jetStream).apiDispatch-fm() /home/travis/gopath/src/github.com/nats-io/nats-server/server/jetstream_api.go:652 +0xcc github.com/nats-io/nats-server/v2/server.(*client).deliverMsg() /home/travis/gopath/src/github.com/nats-io/nats-server/server/client.go:3181 +0xbde github.com/nats-io/nats-server/v2/server.(*client).processMsgResults() /home/travis/gopath/src/github.com/nats-io/nats-server/server/client.go:4164 +0xe1e github.com/nats-io/nats-server/v2/server.(*client).processInboundLeafMsg() /home/travis/gopath/src/github.com/nats-io/nats-server/server/leafnode.go:2183 +0x7eb github.com/nats-io/nats-server/v2/server.(*client).processInboundMsg() /home/travis/gopath/src/github.com/nats-io/nats-server/server/client.go:3498 +0xb1 github.com/nats-io/nats-server/v2/server.(*client).parse() /home/travis/gopath/src/github.com/nats-io/nats-server/server/parser.go:497 +0x3886 github.com/nats-io/nats-server/v2/server.(*client).readLoop() /home/travis/gopath/src/github.com/nats-io/nats-server/server/client.go:1228 +0x1669 github.com/nats-io/nats-server/v2/server.(*Server).createLeafNode.func1() /home/travis/gopath/src/github.com/nats-io/nats-server/server/leafnode.go:904 +0x5d ================== testing.go:1152: race detected during execution of test ``` Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
NATS is a simple, secure and performant communications system for digital systems, services and devices. NATS is part of the Cloud Native Computing Foundation (CNCF). NATS has over 40 client language implementations, and its server can run on-premise, in the cloud, at the edge, and even on a Raspberry Pi. NATS can secure and simplify design and operation of modern distributed systems.
Documentation
- Official documentation
- FAQ
- Watch a video overview of NATS to learn more about its origin story and design philosophy.
Contact
- Twitter: Follow us on Twitter!
- Google Groups: Where you can ask questions
- Slack: Click here to join. You can ask question to our maintainers and to the rich and active community.
Contributing
If you are interested in contributing to NATS, read about our...
Roadmap
The NATS product roadmap can be found here.
Security
Security Audit
A third party security audit was performed by Cure53, you can see the full report here.
Reporting Security Vulnerabilities
If you've found a vulnerability or a potential vulnerability in the NATS server, please let us know at nats-security.
License
Unless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.
