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

Release 17.0.1 #612

Open
antonshkurenko opened this issue Jan 29, 2021 · 5 comments
Open

Release 17.0.1 #612

antonshkurenko opened this issue Jan 29, 2021 · 5 comments

Comments

@antonshkurenko
Copy link

Please, release next version, because this one commit 5d6ba66 ahead of 17.0.0 tag fixes ipc pubsub. Your example https://github.com/paritytech/jsonrpc/blob/master/pubsub/more-examples/examples/pubsub_ipc.rs doesn't work on 17.0.0, but works on that (latest at the moment of writing) commit

@antonshkurenko
Copy link
Author

How to reproduce (for macos):

nc -U test.ipc
{"id":1,"jsonrpc":"2.0","method":"subscribe_hello"}

On latest commit it starts spamming with {"jsonrpc":"2.0","method":"hello","params":[10]}, but on 17.0.0 it returns {"jsonrpc":"2.0","result":5,"id":1} and then nothing

@antonshkurenko
Copy link
Author

Also, is it ok, that it returns no id here {"jsonrpc":"2.0","method":"hello","params":[10]} ?

Logs of the rust client are also full of

WARN [jsonrpc_client_transports::transports::duplex] Got unexpected response with id Null (None)

@antonshkurenko
Copy link
Author

I've created issue a bit earlier (#611), could you please provide a working example? I wrote primitive sample:

let mut client = ...;

let mut rt = tokio::runtime::Runtime::new().unwrap();

rt.block_on(async move {
    let mut result = client
        .subscribe(
           ...
       )
       .unwrap();

    while let Some(value) = result.next().await {
        println!( // <- this never happens
            "Listening"
        );
     }
});

I see in logs (I've attached impl for log crate), that my requests are incoming, but they are lost here:

impl<TSink, TStream> Future for Duplex<TSink, TStream>

...

fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {

...

log::warn!("Got unexpected response with id {:?} ({:?})", id, sid_and_method);

Somehow either this parses incorrectly or somewher else doesn't work or I don't understand:

let (id, result, method, sid) = super::parse_response(&response_str)?;

@antonshkurenko
Copy link
Author

Attaching logs right after server notifies with new data:

Notifying:

let mut sink = subscriber
    .assign_id(SubscriptionId::String(random_id()))
    .unwrap();

for i in 0..5 {
    tokio::time::delay_for(std::time::Duration::from_secs(2)).await;

    sink.notify(jsonrpc_core::Params::Array(vec![
        Value::Number(3.into()),
        Value::Number(4.into()),
    ]))
    .expect("sent second chunk");
}   
2021-01-29 17:45:20,215 TRACE [tokio_util::codec::framed_write] flushing framed transport
2021-01-29 17:45:20,215 TRACE [tokio_util::codec::framed_write] writing; remaining=49
2021-01-29 17:45:20,216 TRACE [tokio_util::codec::framed_write] framed transport flushed
2021-01-29 17:45:20,216 DEBUG [jsonrpc_client_transports::transports::duplex] handle requests from client
2021-01-29 17:45:20,216 DEBUG [jsonrpc_client_transports::transports::duplex] handle stream
2021-01-29 17:45:20,216 TRACE [tokio_util::codec::framed_read] attempting to decode a frame
2021-01-29 17:45:20,216 TRACE [tokio_util::codec::framed_read] frame decoded from buffer
2021-01-29 17:45:20,216 DEBUG [jsonrpc_client_transports::transports::duplex] incoming: 
{"jsonrpc":"2.0","method":"sub1","params":[3,4]}
2021-01-29 17:45:20,216 DEBUG [jsonrpc_client_transports::transports::duplex] id: Null (sid: None) result: Ok(Array([Number(3), Number(4)])) method: Some("sub1")
2021-01-29 17:45:20,216 TRACE [tokio_util::codec::framed_read] attempting to decode a frame
2021-01-29 17:45:20,217 DEBUG [jsonrpc_client_transports::transports::duplex] handle incoming
2021-01-29 17:45:20,217 WARN  [jsonrpc_client_transports::transports::duplex] Got unexpected response with id Null (None)
2021-01-29 17:45:20,217 DEBUG [jsonrpc_client_transports::transports::duplex] handle outgoing
2021-01-29 17:45:20,217 DEBUG [jsonrpc_client_transports::transports::duplex] handle sink
2021-01-29 17:45:20,217 TRACE [tokio_util::codec::framed_write] flushing framed transport
2021-01-29 17:45:20,217 TRACE [tokio_util::codec::framed_write] framed transport flushed
2021-01-29 17:45:20,217 DEBUG [jsonrpc_client_transports::transports::duplex] channel is none: false
outgoing: 0
incoming: 0
pending_requests: 0
subscriptions: 1

@antonshkurenko
Copy link
Author

antonshkurenko commented Feb 1, 2021

For anyone, who will google it inside issues, or wherever else:

To make it work from client side, you need to pass "subscription" key (same id, as you pass into assign_id method) from the server, for example:

let mut sink = subscriber
    .assign_id(SubscriptionId::String(id.to_owned()))
    .unwrap();

sink.notify(jsonrpc_core::Params::Map(
    [
        ("subscription".to_owned(), Value::String(id.to_owned())),
        ("test".to_owned(), Value::String("test".to_owned())),
    ]
    .iter()
    .cloned()
    .collect(),
));

It's needed here:

https://github.com/paritytech/jsonrpc/blob/master/core-client/transports/src/transports/mod.rs#L88

"subcription" key I took in its implementation:

https://github.com/paritytech/jsonrpc/blob/master/core-client/transports/src/transports/mod.rs#L125-L136

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

No branches or pull requests

1 participant