Git Product home page Git Product logo

Comments (8)

kflansburg avatar kflansburg commented on June 2, 2024 3

Yep, I think it would be reasonable to add that to the Rust API. Also looks like we need to add it to our JavaScript docs.

from workers-rs.

kflansburg avatar kflansburg commented on June 2, 2024

This matches the behavior of the JavaScript API, which returns from connect immediately (it is not a Promise), and thus does not indicate whether the connection has been established with the remote server. Errors are then propagated when trying to read / write from the socket.

from workers-rs.

cmmarslender avatar cmmarslender commented on June 2, 2024

This matches the behavior of the JavaScript API, which returns from connect immediately (it is not a Promise), and thus does not indicate whether the connection has been established with the remote server. Errors are then propagated when trying to read / write from the socket.

So thats generally fine, but I was also seeing a write not fail on a socket that didn't actually have an open port, unless I did this wrong somehow.

    let mut socket = Socket::builder()
        .secure_transport(SecureTransport::Off)
        .connect(&connecting_ip, port)
        .map_err(|_| worker::Error::from("Could not create socket"))?;

    socket
        .write(b"GET / HTTP/1.0\r\nHost: example.com\r\n\r\n")
        .await
        .map_err(|_| worker::Error::from("Could not write to socket"))?;

This write doesn't fail for me, even on a closed port, and it sounds like it should err?

from workers-rs.

kflansburg avatar kflansburg commented on June 2, 2024

Does reading return an error? I think it should error, but I will have to check the JavaScript behavior.

from workers-rs.

cmmarslender avatar cmmarslender commented on June 2, 2024

Reading returns an error in most cases. There are certain types of applications where this doesn't seem to be particularly reliable though.

I did some testing in node earlier, and while the socket.connect call itself does not return a promise, you are able to attach event listeners to events like connect, timeout, and error which enable getting at this info more reliably than writing then trying to read. It would be nice to have some way to get at this in Rust (and I was tinkering a bit in JS with workers, and wasn't able to get it to work in that context either). Node test code here https://gist.github.com/cmmarslender/145a929163d8f3501490bf00bed2e993

I think my current rust implementation covers most of the cases I need it to cover, but it would be nice if this could eventually work with just connect and an error there, or attaching an on connect/error/timeout handler, or perhaps some other solution, that doesn't require having to write and read.

from workers-rs.

kflansburg avatar kflansburg commented on June 2, 2024

@dom96 thoughts on this behavior?

from workers-rs.

dom96 avatar dom96 commented on June 2, 2024

I did some testing in node earlier, and while the socket.connect call itself does not return a promise, you are able to attach event listeners to events like connect, timeout, and error which enable getting at this info more reliably than writing then trying to read

We now have an opened promise that can be used for this purpose. It should get rejected if the connection fails to be opened and that shouldn't require any reads/writes to happen.

As for the write not failing, I believe that is expected (for the same reason connect doesn't return a promise which waits for the connection result) and the error ends up in the closed promise instead.

from workers-rs.

cmmarslender avatar cmmarslender commented on June 2, 2024

I did some testing in node earlier, and while the socket.connect call itself does not return a promise, you are able to attach event listeners to events like connect, timeout, and error which enable getting at this info more reliably than writing then trying to read

We now have an opened promise that can be used for this purpose. It should get rejected if the connection fails to be opened and that shouldn't require any reads/writes to happen.

As for the write not failing, I believe that is expected (for the same reason connect doesn't return a promise which waits for the connection result) and the error ends up in the closed promise instead.

is it possible to get at the opened promise in some way from Rust, and if so, are there docs or an example on this somewhere? I haven't seen anything, but may be looking in the wrong places.

from workers-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.