Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can cause a client.Call rpc to return an error in Go (golang)?

Tags:

go

rpc

When does c.Call(...) return a non-nil value?

Can the c.Call(...) only return an error when a network failure occurs (packets lost or timed out or something along those lines)?

If the server srv crashes, will c.Call(...) return an error?

Specifically, can c.Call(...) return an error AFTER the request successfully arrived at srv but BEFORE the rpcname handler function returns?

import (
    "net/rpc"
    "fmt"
)

func call(srv string, rpcname string, args interface{}, reply interface{}) bool {
    c, errx := rpc.Dial("unix", srv)
    if errx != nil {
        return false
    }
    defer c.Close()

    err := c.Call(rpcname, args, reply)
    if err == nil {
        return true
    }

    fmt.Println(err)
    return false
}
like image 576
Pedro Cattori Avatar asked Oct 21 '22 12:10

Pedro Cattori


1 Answers

If you have a look at client.go in the source code for net/rpc you'll see quite a few lines where call.Error is set. These should show you all of the conditions under which a Call will return an error.

Many of them are generated upon encountering errors from ClientCodec.WriteRequest and ClientCodec.ReadResponseBody. See the ClientCodec docs for more details.

There are also a couple of possible errors for encountering unexpected EOF, and ErrShutdown when the client is closing.

like image 196
Intermernet Avatar answered Oct 27 '22 09:10

Intermernet