Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

race in handleShutdown #1781

Closed
bgadrian opened this issue Nov 4, 2018 · 1 comment · Fixed by #1805
Closed

race in handleShutdown #1781

bgadrian opened this issue Nov 4, 2018 · 1 comment · Fixed by #1805

Comments

@bgadrian
Copy link

bgadrian commented Nov 4, 2018

Problem statement

When running the server with -race flag, and sending the intrerupt signal CTRL+C, an error occurs

Swagger specification

https://github.com/bgadrian/pseudoservice/blob/master/swagger.yaml

Steps to reproduce

Simple HTTP server, on port 8080, run local.

go run -race main.go CTRL+C

Environment

swagger version: 0.17.2
go version: 1.11.1
OS: Ubuntu 17

race:
Read: servers := *serversPtr
Write: servers = append(servers, httpServer)
2nd race:
Read: server := servers[i]
Write: servers = append(servers, httpServer)

^C2018/11/04 20:31:15 Shutting down... 
==================
WARNING: DATA RACE
Read at 0x00c000200020 by goroutine 16:
  github.com/bgadrian/pseudoservice/restapi.(*Server).handleShutdown()
      /srv/go/pseudoservice/restapi/server.go:418 +0xba

Previous write at 0x00c000200020 by main goroutine:
  github.com/bgadrian/pseudoservice/restapi.(*Server).Serve()
      /srv/go/pseudoservice/restapi/server.go:229 +0x1c4d
  main.main()
      /srv/go/pseudoservice/cmd/pseudo-service-server/main.go:53 +0x5a1

Goroutine 16 (running) created at:
  github.com/bgadrian/pseudoservice/restapi.(*Server).Serve()
      /srv/go/pseudoservice/restapi/server.go:178 +0x212
  main.main()
      /srv/go/pseudoservice/cmd/pseudo-service-server/main.go:53 +0x5a1
==================
==================
WARNING: DATA RACE
Read at 0x00c000260010 by goroutine 16:
  github.com/bgadrian/pseudoservice/restapi.(*Server).handleShutdown()
      /srv/go/pseudoservice/restapi/server.go:425 +0x1a5

Previous write at 0x00c000260010 by main goroutine:
  github.com/bgadrian/pseudoservice/restapi.(*Server).Serve()
      /srv/go/pseudoservice/restapi/server.go:229 +0x1c17
  main.main()
      /srv/go/pseudoservice/cmd/pseudo-service-server/main.go:53 +0x5a1

Goroutine 16 (running) created at:
  github.com/bgadrian/pseudoservice/restapi.(*Server).Serve()
      /srv/go/pseudoservice/restapi/server.go:178 +0x212
  main.main()
      /srv/go/pseudoservice/cmd/pseudo-service-server/main.go:53 +0x5a1
==================
2018/11/04 20:31:15 Stopped serving pseudo service at http://127.0.0.1:8080
Found 2 data race(s)
exit status 66
@fredbi
Copy link
Contributor

fredbi commented Nov 18, 2018

Tested this. Moving the append(servers, ...) statements just before launching the go routines solves the issue.

@fredbi fredbi self-assigned this Nov 18, 2018
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 18, 2018
* fixes go-swagger#1781

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 19, 2018
* fixes go-swagger#1781

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 22, 2018
* fixes go-swagger#1781

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 28, 2018
* fixes go-swagger#1781

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/go-swagger that referenced this issue Nov 28, 2018
* fixes go-swagger#1781

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit that referenced this issue Nov 28, 2018
* fixes #1781

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants