Comments (8)
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.
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.
This matches the behavior of the JavaScript API, which returns from
connect
immediately (it is not aPromise
), 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.
Does reading return an error? I think it should error, but I will have to check the JavaScript behavior.
from workers-rs.
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.
@dom96 thoughts on this behavior?
from workers-rs.
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.
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 reasonconnect
doesn't return a promise which waits for the connection result) and the error ends up in theclosed
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)
- Captcha error
- [BUG] All panics become "A hanging Promise was canceled" error HOT 2
- [BUG] worker::Secret documentation is broken
- [BUG] `Rc<RefCell<wasm_bindgen_futures::Inner>>` cannot be sent between threads safely HOT 20
- [Feature] Enable DurableObject Storage's `transaction` API
- Unable to use custom methods for CORS HOT 1
- [Feature] Contribution Guidance HOT 6
- [BUG] http feature is not additive HOT 2
- Make workers-kv a crate in this workspace HOT 1
- Introduce tests for DO transaction API
- Improve Release CI HOT 1
- [BUG] New http return types always use chunked transfer encoding HOT 6
- [Feature] Make `chrono-tz` an optional dependency HOT 8
- Improve top-level error handling HOT 3
- [BUG] `http` feature is not named accurately. HOT 1
- [BUG] `worker-kv` is not released together with other crates HOT 3
- [Feature] Add #[worker::trait_send] for async_trait
- 🤾♀️ [Feature] Most interop methods should be marked with `catch` HOT 4
- worker-kv does not serialize struct metadata HOT 3
- [BUG] CORS Access-Control-Allow-Origin set wrong if using multiple origins
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workers-rs.