gorpc icon indicating copy to clipboard operation
gorpc copied to clipboard

Client connection cause server panic on ARM

Open IS-Martin opened this issue 3 years ago • 2 comments

Hi,

As title, it seems to relate to https://github.com/golang/go/issues/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

IS-Martin avatar Dec 08 '22 06:12 IS-Martin

you should fork and fix this issue imho, the repo hasn't been active for 7 years.

aea7 avatar Feb 14 '23 10:02 aea7

I see. Thank you for the info.

Should I close this issue, then?

IS-Martin avatar Feb 15 '23 01:02 IS-Martin