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

RPC example code appears incorrect #203

Closed
frumioj opened this issue Dec 15, 2021 · 12 comments
Closed

RPC example code appears incorrect #203

frumioj opened this issue Dec 15, 2021 · 12 comments
Labels
Milestone

Comments

@frumioj
Copy link
Contributor

frumioj commented Dec 15, 2021

When I copy and paste the RPC client example code:

    f, free := hf.NewSha1(ctx, nil)
    defer free()

    // 'NewSha1' returns a future, which allows us to pipeline calls to
    // returned values before they are actually delivered.  Here, we issue
    // calls to an as-of-yet-unresolved Sha1 instance.
    s := f.Hash()

    // s refers to a remote Hash.  Method calls are delivered in order.
    f, free = s.Write(ctx, func(p hashes.Hash_write_Params) error {
        return p.SetData([]byte("Hello, "))
    })
    defer free()
    f, free = s.Write(ctx, func(p hashes.Hash_write_Params) error {
        return p.SetData([]byte("World!"))
    })
    defer free()

    // Get the sum, waiting for the result.
    f, free = s.Sum(ctx, nil)
    defer free()
    result, err := f.Struct()
    if err != nil {
        return err
    }

    // Display the result.
    sha1Val, err := result.Hash()

I get lots of errors, since the futures return different types. I tried assigning to different variables which makes the program compile, but it doesn't return a result when I do that.

./hashesserver.go:97:10: cannot assign hashes.Hash_write_Results_Future to f (type hashes.HashFactory_newSha1_Results_Future) in multiple assignment
./hashesserver.go:97:10: cannot use hashes.Hash_write_Results_Future value as type hashes.HashFactory_newSha1_Results_Future in assignment
./hashesserver.go:102:10: cannot assign hashes.Hash_write_Results_Future to f (type hashes.HashFactory_newSha1_Results_Future) in multiple assignment
./hashesserver.go:102:10: cannot use hashes.Hash_write_Results_Future value as type hashes.HashFactory_newSha1_Results_Future in assignment
./hashesserver.go:108:10: cannot assign hashes.Hash_sum_Results_Future to f (type hashes.HashFactory_newSha1_Results_Future) in multiple assignment
./hashesserver.go:108:10: cannot use hashes.Hash_sum_Results_Future value as type hashes.HashFactory_newSha1_Results_Future in assignment
./hashesserver.go:119:15: assignment mismatch: 2 variables but result.Hash returns 1 value
@lthibault
Copy link
Collaborator

Can you paste your go.mod file? I suspect you may be pulling in an older version.

@frumioj
Copy link
Contributor Author

frumioj commented Dec 15, 2021

module test

go 1.17

require (
hashes v1.0.0
capnproto.org/go/capnp/v3 v3.0.0-alpha.1
golang.org/x/net v0.0.0-20211209124913-491a49abca63
)

replace (
hashes v1.0.0 => ./hashes
)

@lthibault
Copy link
Collaborator

lthibault commented Dec 15, 2021

Thanks! Ok, two more quick things:

  1. Can you check the import path for capnp in the generated Go code? Can you confirm that it contians the v3 suffix?
  2. Can you run the following command to make sure you have the latest version of the plugin compiler and try again?
rm `which capnpc-go`
GO111MODULE=off go install capnproto.org/go/capnp/v3/capnpc-go@latest

Failing that, I'll take a deeper look but I probably won't have time until the weekend.

( ⚠️ EDIT: updated command)

@frumioj
Copy link
Contributor Author

frumioj commented Dec 15, 2021

Thanks for your help Louis. Answers inline below:

On 12/15/21 12:25, Louis Thibault wrote:

Thanks! Ok, two more quick things:

  1. Can you check the import path for capnp in the generated Go code?
    Can you confirm that it contians the |v3| suffix?

It does:

johnk@REGEN:~/src/foo$ head hashes/hashes.capnp.go
// Code generated by capnpc-go. DO NOT EDIT.

package hashes

import (
    capnp "capnproto.org/go/capnp/v3"
    text "capnproto.org/go/capnp/v3/encoding/text"
    schemas "capnproto.org/go/capnp/v3/schemas"
    server "capnproto.org/go/capnp/v3/server"
    context "context"
johnk@REGEN:~/src/foo$
  1. Can you run the following command to make sure you have the latest
    version of the plugin compiler and try again?

|rm which capnpc-go GO111MODULE=off go get -u capnproto.org/go/capnp/v3/ |

Trying on a new VM (no capnpc-go), I get an error:

[johnk@fedora ~]$ GO111MODULE=off go get -u capnproto.org/go/capnp/v3/
cannot find package "capnproto.org/go/capnp/v3" in any of:
    /usr/lib/golang/src/capnproto.org/go/capnp/v3 (from $GOROOT)
    /home/johnk/go/src/capnproto.org/go/capnp/v3 (from $GOPATH)

However, it does install something:

[johnk@fedora ~]$ ls -la ~/go/src/capnproto.org/go/capnp/
total 428
drwxrwxr-x. 1 johnk johnk  1074 Dec 15 14:17 .
drwxrwxr-x. 1 johnk johnk    10 Dec 15 14:17 ..
-rw-rw-r--. 1 johnk johnk  6020 Dec 15 14:17 address.go
-rw-rw-r--. 1 johnk johnk  2515 Dec 15 14:17 address_test.go
-rw-rw-r--. 1 johnk johnk 20578 Dec 15 14:17 answer.go
-rw-rw-r--. 1 johnk johnk  5753 Dec 15 14:17 answer_test.go
-rw-rw-r--. 1 johnk johnk   998 Dec 15 14:17 AUTHORS
-rw-rw-r--. 1 johnk johnk  4182 Dec 15 14:17 canonical.go
-rw-rw-r--. 1 johnk johnk  5460 Dec 15 14:17 canonical_test.go
-rw-rw-r--. 1 johnk johnk 21179 Dec 15 14:17 capability.go
-rw-rw-r--. 1 johnk johnk 13659 Dec 15 14:17 capability_test.go
drwxrwxr-x. 1 johnk johnk   210 Dec 15 14:17 capnpc-go
-rw-rw-r--. 1 johnk johnk 10999 Dec 15 14:17 CHANGELOG.md
-rw-rw-r--. 1 johnk johnk  1377 Dec 15 14:17 CONTRIBUTORS
-rw-rw-r--. 1 johnk johnk 12140 Dec 15 14:17 doc.go
drwxrwxr-x. 1 johnk johnk     8 Dec 15 14:17 encoding
-rw-rw-r--. 1 johnk johnk  1283 Dec 15 14:17 error.go
-rw-rw-r--. 1 johnk johnk  2861 Dec 15 14:17 example_test.go
drwxrwxr-x. 1 johnk johnk   138 Dec 15 14:17 .git
drwxrwxr-x. 1 johnk johnk    40 Dec 15 14:17 .github
-rw-rw-r--. 1 johnk johnk   154 Dec 15 14:17 .gitignore
-rw-rw-r--. 1 johnk johnk   161 Dec 15 14:17 go.mod
-rw-rw-r--. 1 johnk johnk  3821 Dec 15 14:17 go.sum
-rw-rw-r--. 1 johnk johnk 54164 Dec 15 14:17 integration_test.go
-rw-rw-r--. 1 johnk johnk  2702 Dec 15 14:17 integrationutil_test.go
drwxrwxr-x. 1 johnk johnk   144 Dec 15 14:17 internal
-rw-rw-r--. 1 johnk johnk  1328 Dec 15 14:17 LICENSE
-rw-rw-r--. 1 johnk johnk 24661 Dec 15 14:17 list.go
-rw-rw-r--. 1 johnk johnk  2999 Dec 15 14:17 list_test.go
-rw-rw-r--. 1 johnk johnk 25810 Dec 15 14:17 message.go
-rw-rw-r--. 1 johnk johnk   170 Dec 15 14:17 message_go18.go
-rw-rw-r--. 1 johnk johnk   201 Dec 15 14:17 message_other.go
-rw-rw-r--. 1 johnk johnk 25270 Dec 15 14:17 message_test.go
-rw-rw-r--. 1 johnk johnk  4550 Dec 15 14:17 msgp_bench_gen_test.go
-rw-rw-r--. 1 johnk johnk  1346 Dec 15 14:17 msgp_bench_test.go
drwxrwxr-x. 1 johnk johnk   174 Dec 15 14:17 pogs
-rw-rw-r--. 1 johnk johnk  9097 Dec 15 14:17 pointer.go
-rw-rw-r--. 1 johnk johnk  7117 Dec 15 14:17 pointer_test.go
-rw-rw-r--. 1 johnk johnk  7423 Dec 15 14:17 rawpointer.go
-rw-rw-r--. 1 johnk johnk 13261 Dec 15 14:17 rawpointer_test.go
-rw-rw-r--. 1 johnk johnk  3716 Dec 15 14:17 readlimit_test.go
-rw-rw-r--. 1 johnk johnk  3793 Dec 15 14:17 README.md
-rwxrwxr-x. 1 johnk johnk   541 Dec 15 14:17 regen.sh
drwxrwxr-x. 1 johnk johnk   372 Dec 15 14:17 rpc
drwxrwxr-x. 1 johnk johnk    50 Dec 15 14:17 schemas
-rw-rw-r--. 1 johnk johnk 11481 Dec 15 14:17 segment.go
-rw-rw-r--. 1 johnk johnk 23700 Dec 15 14:17 segment_test.go
drwxrwxr-x. 1 johnk johnk    94 Dec 15 14:17 server
drwxrwxr-x. 1 johnk johnk    66 Dec 15 14:17 std
-rw-rw-r--. 1 johnk johnk  9401 Dec 15 14:17 struct.go

Perhaps the install is not working as expected?

[johnk@fedora ~]$ go version
go version go1.16.8 linux/amd64
  • johnk

@zenhack
Copy link
Contributor

zenhack commented Dec 15, 2021 via email

@zenhack
Copy link
Contributor

zenhack commented Dec 15, 2021 via email

@frumioj
Copy link
Contributor Author

frumioj commented Dec 16, 2021

Thanks - but yeah, that doesn't help ;)

@lthibault
Copy link
Collaborator

lthibault commented Dec 16, 2021 via email

@zenhack
Copy link
Contributor

zenhack commented Dec 17, 2021

Finally found time to sit down and try this out. What does your (building) server code look like? I noticed it looks like in addition to erroneously reusing variable names in the client, the server code in https://github.com/capnproto/go-capnproto2/wiki/Getting-Started#remote-calls-using-interfaces is using the v2 api, so that doesn't build for me either.

(I suspect in the case of the server we went through and did a find & replace for the import path at some point, but neglected to actually update the example for v3).

@frumioj
Copy link
Contributor Author

frumioj commented Dec 17, 2021

Finally found time to sit down and try this out. What does your (building) server code look like?

My server and client were cut and pasted from your "hashes" example. Since I was having problems writing my own server, I decided to try building your example, and making it into a full program. So I made a go module, fixed the import paths etc. and then tried to build it... hence this issue :)

I noticed it looks like in addition to erroneously reusing variable names in the client, the server code in https://github.com/capnproto/go-capnproto2/wiki/Getting-Started#remote-calls-using-interfaces is using the v2 api, so that doesn't build for me either.

(I suspect in the case of the server we went through and did a find & replace for the import path at some point, but neglected to actually update the example for v3).

OK. You can see my full example so far at https://github.com/frumioj/go-capnproto2/tree/main/example/hashes

If there are any hints about where I could get started to change this to work, please let me know.

@frumioj
Copy link
Contributor Author

frumioj commented Dec 17, 2021

It might be worth dropping into the Matrix support channel, as I suspect there will be a bit of trial an error here. Ian and I are on US Eastern time. https://matrix.to/#/!pLcnVUHHRZrUPscloW:matrix.org?via=matrix.org https://matrix.to/#/!pLcnVUHHRZrUPscloW:matrix.org?via=matrix.org

Not sure I have time for real-time comms at the moment, but thanks for that. Will try to appear there...

@lthibault lthibault added the docs label Dec 19, 2021
@lthibault lthibault added this to the 3.0 milestone Dec 19, 2021
@lthibault
Copy link
Collaborator

Fixed via #204

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants