Skip to content

runtime/race: doesn't support the plugin package #24245

Open

Description

@tiborvass

What did you do?

// plugin/plugin.go

package main

import (
	"os"
	"time"
)

var counter int

func main() {
	os.Exit(Main())
}

func Main() int {
	go func() {
		counter++
	}()
	time.Sleep(500 * time.Millisecond)
	return counter
}
// plugin-runner.go

package main

import (
	"os"
	"plugin"
)

func main() {
	p, err := plugin.Open(os.Args[1])
	if err != nil {
		panic(err)
	}
	sym, err := p.Lookup("Main")
	if err != nil {
		panic(err)
	}
	f := sym.(func() int)
	_ = f()
}
$ go build -o plugin/plugin.so -race -buildmode=plugin plugin/plugin.go
$ go run -race plugin-runner.go plugin/plugin.so

What did you expect to see?

A DATA RACE output similar to this one:

$ go run -race plugin/plugin.go
==================
WARNING: DATA RACE
Read at 0x00000051da38 by main goroutine:
  main.Main()
      /go/src/github.com/tiborvass/goissues/plugin/race-nodetect/plugin/plugin.go:19 +0x5f
  main.main()
      /go/src/github.com/tiborvass/goissues/plugin/race-nodetect/plugin/plugin.go:11 +0x2f

Previous write at 0x00000051da38 by goroutine 6:
  main.Main.func1()
      /go/src/github.com/tiborvass/goissues/plugin/race-nodetect/plugin/plugin.go:16 +0x56

Goroutine 6 (finished) created at:
  main.Main()
      /go/src/github.com/tiborvass/goissues/plugin/race-nodetect/plugin/plugin.go:15 +0x42
  main.main()
      /go/src/github.com/tiborvass/goissues/plugin/race-nodetect/plugin/plugin.go:11 +0x2f
==================
exit status 1

What did you see instead?

No output. I reproduced it 100% on both linux and darwin.

System details

go version go1.10 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build269754766=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.10 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.10
uname -sr: Linux 4.9.75-linuxkit-aufs
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Debian GLIBC 2.24-11+deb9u1) stable release version 2.24, by Roland McGrath et al.

Activity

  1. mvdan commented on Mar 4, 2018

    @mvdan
    Member
  2. added
    NeedsInvestigation
    on Mar 4, 2018
  3. changed the title [-]Race detector does not detect data races in a loaded plugin[/-] [+]runtime/race: doesn't support the plugin package[/+] on Mar 5, 2018
  4. added
    FeatureRequest
    on Mar 5, 2018
  5. added this to the Unplanned milestone on Mar 5, 2018
  6. szuecs commented on Feb 26, 2019

    @szuecs

    Sounds like an issue to our production application, which enables users to build their own Go plugins to enhance the application.

    It would be nice if this would get a fix. Is this complicated or just not prioritized yet, because of plugin is not first class anyhow?

  7. ianlancetaylor commented on Feb 26, 2019

    @ianlancetaylor
    Contributor

    It's not prioritized. It would help if somebody could figure out what the actual problem is. It may be obvious, it may not; I don't know.

  8. itsmontoya commented on May 17, 2020

    @itsmontoya

    I've tested this by building the core app with --race, the plugin built with --race, and both built with --race and I've encountered no success. If anyone on the go team needs some examples. The vroomy team can provide some! :)

  9. added
    compiler/runtime
    on Jul 7, 2022
  10. adonespitogo commented on Jan 5, 2023

    @adonespitogo

    In my case, a simple plugin that runs an http server with a simple handler func for root path / always produces data race when put under wrk stress test.

    // plugin.go
    func Init() {
      http.HandleFunc("/", func (w http.ResponseWriter,  _  *http.Request) {
        fmt.Fprint(w, "Hello World")
      })
      http.ListenAndServe(":3000", nil)
    }
    
    // load-plugin.go
    func main () {
      p, err := plugin.Open("plugin.so")
      if err != nil {
        panic(err)
      }
      sym, err := p.Lookup("Init")
      if err != nil {
        panic(err)
      }
      init := sym.(func())
      init()
    }

    Error:

    ==================                                                                                      
    WARNING: DATA RACE                                                                                      
    Write at 0x00c000703380 by goroutine 513:                                                               
      bufio.(*Writer).Reset()                                                                               
          /Users/adonesp/.gvm/gos/go1.19.4/src/bufio/bufio.go:616 +0x100                                    
      net/http.newBufioWriterSize()                                                                         
          /Users/adonesp/.gvm/gos/go1.19.4/src/net/http/server.go:844 +0x84                                 
      net/http.(*conn).readRequest()                                                                        
          /Users/adonesp/.gvm/gos/go1.19.4/src/net/http/server.go:1061 +0x1388                              
      net/http.(*conn).serve()                                                                              
          /Users/adonesp/.gvm/gos/go1.19.4/src/net/http/server.go:1916 +0x468                               
      net/http.(*Server).Serve.func3()                                                                      
          /Users/adonesp/.gvm/gos/go1.19.4/src/net/http/server.go:3102 +0x4c                                
                                                                                                            
    Previous read at 0x00c000703380 by goroutine 289:                                                       
      bufio.(*Writer).Write()                                                                               
          /Users/adonesp/.gvm/gos/go1.19.4/src/bufio/bufio.go:678 +0x24c                                    
      net/http.(*response).write()                                                                          
          /Users/adonesp/.gvm/gos/go1.19.4/src/net/http/server.go:1640 +0x264                               
      net/http.(*response).Write()                                                                          
          /Users/adonesp/.gvm/gos/go1.19.4/src/net/http/server.go:1598 +0x4c                                
      fmt.Fprint()                                                                                          
          /Users/adonesp/.gvm/gos/go1.19.4/src/fmt/print.go:243 +0x84                                       
      github.com/AdoPiSoft/base/web.SetupRoutes.func1()                                                     
          /Users/adonesp/Projects/adopisoft-v6/base/web/routes.go:30 +0x68  
      net/http.HandlerFunc.ServeHTTP()                                                                      
          /Users/adonesp/.gvm/gos/go1.19.4/src/net/http/server.go:2109 +0x48                                
      net/http.(*ServeMux).ServeHTTP()                                                                      
          /Users/adonesp/.gvm/gos/go1.19.4/src/net/http/server.go:2487 +0x9c                                
      net/http.serverHandler.ServeHTTP()                                                                    
          /Users/adonesp/.gvm/gos/go1.19.4/src/net/http/server.go:2947 +0x4f4                               
      net/http.(*conn).serve()                                                                              
          /Users/adonesp/.gvm/gos/go1.19.4/src/net/http/server.go:1991 +0x8d4                               
      net/http.(*Server).Serve.func3()                                                                      
          /Users/adonesp/.gvm/gos/go1.19.4/src/net/http/server.go:3102 +0x4c 
    
  11. ExtraE113 commented on Aug 7, 2024

    @ExtraE113
    Contributor

    Any update on when this might be fixed? I just lost like 4 hours to this problem.

  12. ianlancetaylor commented on Aug 7, 2024

    @ianlancetaylor
    Contributor

    Honestly plugins are barely supported at all. If somebody sends in a fix we will review it, but it's unlikely that anybody on the core Go team is going to work on this any time soon. Sorry.

  13. ExtraE113 commented on Aug 7, 2024

    @ExtraE113
    Contributor

    Good to know, thanks. Any chance this could make it into the docs on plugins?

    Edit: I've opened a PR #68792

  14. gopherbot commented on Aug 8, 2024

    @gopherbot
    Contributor

    Change https://go.dev/cl/604275 mentions this issue: plugin: include a warning about race detector compatability in docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestNeedsInvestigationRaceDetectorcompiler/runtimehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions