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

net/rpc: API Call() is not working as expected #29360

Closed
SagarPuneria opened this issue Dec 20, 2018 · 4 comments
Closed

net/rpc: API Call() is not working as expected #29360

SagarPuneria opened this issue Dec 20, 2018 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@SagarPuneria
Copy link

SagarPuneria commented Dec 20, 2018

What version of Go are you using (go version)?

$ go version
go version go1.11.4 windows/386

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

Windows 10, 64 bit

What did you do?

I am using client.Call(serviceMethod string, args interface{}, reply interface{}) in my code for implementing HTTP RPC client program, where i have passed reference address of variable in both second parameter args(interface type) and third parameter reply(interface type). So that changes made to the receiver's methods in the DefaultServer get reflected outside the client.Call() method.
HTTP RPC client example

Output:
arg:"go version is go1.11.3 is not latest"
reply:"go version is go1.11.4 is latest"

HTTP RPC server example

Output:
Inside StringModify

What did you expect to see?

I expected to see the same string values to args and reply(both are interface type) after successfully calling client.Call(). Since i assigned same value at line number 20 as shown in HTTP RPC server example

What did you see instead?

After calling client.Call() args and reply string values are different. I see only reply get modified but not args.

@SagarPuneria
Copy link
Author

CC @bradfitz

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 21, 2018
@ALTree ALTree added this to the Go1.13 milestone Dec 21, 2018
@as
Copy link
Contributor

as commented Dec 23, 2018

I don't think this is an implementation bug, the documentation says the method should be of the form:

func (t *T) MethodName(argType T1, replyType *T2) error

I interpret that as T1 being immutable through the RPC. I would be surprised if T1 was mutated even when it is a pointer. The Arith example uses both arguments as pointer types, perhaps this suggests mutability.

	type Arith int

	func (t *Arith) Multiply(args *Args, reply *int) error {
		*reply = args.A * args.B
		return nil
	}

	func (t *Arith) Divide(args *Args, quo *Quotient) error {
		if args.B == 0 {
			return errors.New("divide by zero")
		}
		quo.Quo = args.A / args.B
		quo.Rem = args.A % args.B
		return nil
	}

Nowhere in the example is args actually modified though. It might be less confusing to make the example have a value type for args to make things unambiguous.

@SagarPuneria
Copy link
Author

@as, thanks for investigating.

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@seankhliao
Copy link
Member

closing as this looks to be working as intended

@golang golang locked and limited conversation to collaborators Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants