forked from cwtch.im/tapir
fix race ondition in base onion service
This commit is contained in:
parent
91a6e17d19
commit
525cacffed
|
@ -20,6 +20,7 @@ type BaseOnionService struct {
|
||||||
id *primitives.Identity
|
id *primitives.Identity
|
||||||
privateKey ed25519.PrivateKey
|
privateKey ed25519.PrivateKey
|
||||||
ls connectivity.ListenService
|
ls connectivity.ListenService
|
||||||
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init initializes a BaseOnionService with a given private key and identity
|
// Init initializes a BaseOnionService with a given private key and identity
|
||||||
|
@ -116,9 +117,12 @@ func (s *BaseOnionService) getNewConnectionID() string {
|
||||||
func (s *BaseOnionService) Listen(app tapir.Application) error {
|
func (s *BaseOnionService) Listen(app tapir.Application) error {
|
||||||
// accepts a new connection
|
// accepts a new connection
|
||||||
// spins off to a connection struct
|
// spins off to a connection struct
|
||||||
|
s.lock.Lock()
|
||||||
ls, err := s.acn.Listen(s.privateKey, 9878)
|
ls, err := s.acn.Listen(s.privateKey, 9878)
|
||||||
s.ls = ls
|
s.ls = ls
|
||||||
log.Debugf("Starting a service on %v ", ls.AddressFull())
|
log.Debugf("Starting a service on %v ", ls.AddressFull())
|
||||||
|
s.lock.Unlock()
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for {
|
for {
|
||||||
conn, err := s.ls.Accept()
|
conn, err := s.ls.Accept()
|
||||||
|
@ -138,6 +142,8 @@ func (s *BaseOnionService) Listen(app tapir.Application) error {
|
||||||
|
|
||||||
// Shutdown closes the service and ensures that any connections are closed.
|
// Shutdown closes the service and ensures that any connections are closed.
|
||||||
func (s *BaseOnionService) Shutdown() {
|
func (s *BaseOnionService) Shutdown() {
|
||||||
|
s.lock.Lock()
|
||||||
|
defer s.lock.Unlock()
|
||||||
s.ls.Close()
|
s.ls.Close()
|
||||||
s.connections.Range(func(key, value interface{}) bool {
|
s.connections.Range(func(key, value interface{}) bool {
|
||||||
connection := value.(tapir.Connection)
|
connection := value.(tapir.Connection)
|
||||||
|
|
|
@ -4,12 +4,18 @@ set -e
|
||||||
pwd
|
pwd
|
||||||
go test -race ${1} -coverprofile=applications.cover.out -v ./applications
|
go test -race ${1} -coverprofile=applications.cover.out -v ./applications
|
||||||
go test -race ${1} -coverprofile=applications.tokenboard.cover.out -v ./applications/tokenboard
|
go test -race ${1} -coverprofile=applications.tokenboard.cover.out -v ./applications/tokenboard
|
||||||
go test -race ${1} -coverprofile=persistence.cover.out -v ./persistence
|
# persistence is broken in WSL
|
||||||
|
if grep -q -v Microsoft /proc/version; then
|
||||||
|
go test -race ${1} -coverprofile=persistence.cover.out -v ./persistence
|
||||||
|
fi
|
||||||
go test -race ${1} -coverprofile=primitives.cover.out -v ./primitives
|
go test -race ${1} -coverprofile=primitives.cover.out -v ./primitives
|
||||||
go test -race ${1} -coverprofile=primitives.auditable.cover.out -v ./primitives/auditable
|
go test -race ${1} -coverprofile=primitives.auditable.cover.out -v ./primitives/auditable
|
||||||
go test -race ${1} -coverprofile=primitives.core.cover.out -v ./primitives/core
|
go test -race ${1} -coverprofile=primitives.core.cover.out -v ./primitives/core
|
||||||
go test -race ${1} -coverprofile=primitives.privacypass.cover.out -v ./primitives/privacypass
|
# persistence is broken in WSL
|
||||||
go test -bench "BenchmarkAuditableStore" -benchtime 1000x primitives/auditable/*.go
|
if grep -q -v Microsoft /proc/version; then
|
||||||
|
go test -race ${1} -coverprofile=primitives.privacypass.cover.out -v ./primitives/privacypass
|
||||||
|
go test -bench "BenchmarkAuditableStore" -benchtime 1000x primitives/auditable/*.go
|
||||||
|
fi
|
||||||
echo "mode: set" > coverage.out && cat *.cover.out | grep -v mode: | sort -r | \
|
echo "mode: set" > coverage.out && cat *.cover.out | grep -v mode: | sort -r | \
|
||||||
awk '{if($1 != last) {print $0;last=$1}}' >> coverage.out
|
awk '{if($1 != last) {print $0;last=$1}}' >> coverage.out
|
||||||
rm -rf *.cover.out
|
rm -rf *.cover.out
|
||||||
|
|
Loading…
Reference in New Issue