Skip to content

Client connection cause server panic on ARM #38

Description

@IS-Martin

Hi,

As title, it seems to relate to golang/go#23345.
Is there any way to avoid this problem?

Here is my test steps.

  1. Sample code
package main

import (
	"log"
	"time"
	"github.com/valyala/gorpc"
)

func main() {
	go func() {
		s := &gorpc.Server{
			// Accept clients on this TCP address.
			Addr: "0.0.0.0:12345",
	
			// Echo handler - just return back the message we received from the client
			Handler: func(clientAddr string, request interface{}) interface{} {
				log.Printf("Obtained request %+v from the client %s\n", request, clientAddr)
				return request
			},
		}
		if err := s.Serve(); err != nil {
			log.Fatalf("Cannot start rpc server: %s", err)
		}	
	}()
		
	c := &gorpc.Client{
		// TCP address of the server.
		Addr: "127.0.0.1:12345",
	}
	c.Start()
	time.Sleep(3 * time.Second)

	// All client methods issuing RPCs are thread-safe and goroutine-safe,
	// i.e. it is safe to call them from multiple concurrently running goroutines.
	resp, err := c.Call("foobar")
	if err != nil {
		log.Fatalf("Error when sending request to server: %s", err)
	}
	if resp.(string) != "foobar" {
		log.Fatalf("Unexpected response from the server: %+v", resp)
	}
	log.Printf("resp: %v", resp)
}
  1. Use go1.9, and build with GOARCH=arm GOARM=7 GOOS=linux go build -o testgorpc ./main.go
  2. Run testgorpc and get panic as the client connects to the server.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x114fc]

goroutine 8 [running]:
sync/atomic.addUint64(0x10598084, 0x1, 0x0, 0x10523708, 0x11afb4)
	/usr/local/go/src/sync/atomic/64bit_arm.go:31 +0x4c
github.com/valyala/gorpc.(*ConnStats).incAcceptCalls(0x10598034)
	/go/src/github.com/valyala/gorpc/conn_stats_generic.go:87 +0x34
github.com/valyala/gorpc.serverHandler(0x10598000, 0x10518300)
	/go/src/github.com/valyala/gorpc/server.go:207 +0x1b0
created by github.com/valyala/gorpc.(*Server).Start
	/go/src/github.com/valyala/gorpc/server.go:158 +0x2e8

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions