Comments (3)
Huh that's surprising. I think you should never get this so long as the provided io
performs blocking I/O (like a TcpStream).
Could you share your code?
from ureq.
Sorry for the late reply, been busy. Will try to create a minimal example.
from ureq.
I found the issue, it happens when there's a really really slow server and the request times out while trying to do a tls handshake.
If you run the server and then start two clients at the same time, one of them will fail with "TimedOut" and the other with "WouldBlock", as the first one that starts will timeout reading the response while the other one times out during the tls handshake.
So it's not really a "bug" per se, ureq does what it is supposed to, but the "WouldBlock" error type is very confusing.
client
static ROOT_CERT_PEM : &str = r#"-----BEGIN CERTIFICATE-----
MIIDcTCCAlmgAwIBAgIURAwA7tQhPBDBQ88AeTljaZjwCbUwDQYJKoZIhvcNAQEL
BQAwTzELMAkGA1UEBhMCU0UxDzANBgNVBAgMBlNjYW5pYTENMAsGA1UEBwwETHVu
ZDENMAsGA1UECgwEQXhpczERMA8GA1UEAwwIdGVzdC5jb20wHhcNMjMxMTEyMTUy
MTA5WhcNMjQxMTEyMTUyMTA5WjBPMQswCQYDVQQGEwJTRTEPMA0GA1UECAwGU2Nh
bmlhMQ0wCwYDVQQHDARMdW5kMQ0wCwYDVQQKDARBeGlzMREwDwYDVQQDDAh0ZXN0
LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIjbuyzMmEbv+RAt
mfq747V+lGTSxMMbNe/o721Ybjt3aSigrazmO8TL9Qy33bWwVGRuizZCcomyJAML
8qPqp5yB6t9u0+jdnOFneQE3PDp5wpel0zUfj9HBhMTbL0NnS3fwTOYS9jGgy2VH
wCWPqT+0TxKBaomR+6khFXwSBOd6xpOfGy2Kb4bdTvMmSgO4jDJ9gHWUnjMuMiWq
mFswIu9ZqxtJoD9iJTC+NG2NlMWZDzTy/Eo6OVyJf6uBUdPEWpDz9cURFvu1QuxL
mKA3wP8l6Xlq17hPnkStzmZnKJCiuToVCjzbjT2fzJy/S3Iid+i1vD6yEV+WogCX
VFFMbM8CAwEAAaNFMEMwEgYDVR0TAQH/BAgwBgEB/wIBAjAOBgNVHQ8BAf8EBAMC
AQYwHQYDVR0OBBYEFAv8JD8ZmZX4RI7lzFHi8u4yS6KHMA0GCSqGSIb3DQEBCwUA
A4IBAQAhQAKFj3IXHjE5TsolKZzFsVFQcph7h76kyhj6nPmdg0rEmb6Qtg4HO5YU
4A+dGx0nJGPLAnLYmDIc7Pn+ZChsZcbcZbm+JBuHKYrueuLvr30lxB5KsoXsqKdB
ME/uFgkwxqdCmNidT6oG2y2TIo+qZKqBWmIgxGdkU73NkvtgQbuVDg3tHYemj0ni
E0NPBpWN0N1tkUO/zjnDnfx2Qog2R1I+XUG3jlikJgXMGhSlsmYifCTHKzuqSb7l
6FrT3Y5nzeBpEL4U9sv0i3JYFHglEwzXUsNBYXg5ejlpXUu4XiTXKgPCqMByVAWx
7KpMXzfJ7W2Zf2J9qJkD24CrKaKi
-----END CERTIFICATE-----"#;
fn request() {
let string = "abcde ".repeat(5);
let root_cert = native_tls::Certificate::from_pem(ROOT_CERT_PEM.as_bytes()).unwrap();
let tls_connector = native_tls::TlsConnector::builder()
.add_root_certificate(root_cert)
.build()
.unwrap();
let agent = ureq::AgentBuilder::new()
.tls_connector(tls_connector.into())
.build();
let req = agent.post("https://192.168.0.8:5000/")
.timeout(std::time::Duration::from_secs(1))
.set("Expect", "100-continue");
let res = req.send(string.as_bytes()).unwrap();
println!("res2: {:?}", res);
assert_eq!(res.status(), 200);
let body = res.into_string().unwrap();
assert_eq!("Hello, world!", body);
}
fn main() {
request();
}
#[test]
fn test_a() {
for i in 1..1000 {simultaneously run
println!("\nRun {i}\n");
request();
}
}
server
#!/usr/bin/env python3
from flask import Flask, request
from werkzeug import serving
from time import sleep
app = Flask(__name__)
@app.route('/', methods = ['POST'])
def a():
body = request.data
sleep(2)
return "Hello, world!"
if __name__=='__main__':
cert_chain_path = "Entity-chain.crt"
priv_key_path = "Entity.key"
ssl_ctx = (cert_chain_path, priv_key_path)
app.use_reloader = False
server = serving.make_server(
host="0.0.0.0",
port=5000,
app=app,
ssl_context=ssl_ctx)
server.serve_forever()
from ureq.
Related Issues (20)
- Support Multipart Forms HOT 1
- Timeout not always respected HOT 5
- Invalid transformation to http::Response<Vec<u8>> for non utf8 response bodies HOT 3
- Example of requesting a continuous stream HOT 1
- Timeout not taking in consideration TimeoutConnect HOT 2
- ureq 2.9.3 fails to compile with errors in `hoot` HOT 3
- `ureq` 2.9.3 compilation fails due to `hoot` requiring rustc 1.65 HOT 4
- Keep-alive is disabled when using SOCKS HOT 1
- Update requirement of `url=2.3.1` HOT 3
- hootbin is a required dependency HOT 2
- Stream panics in drop during test
- Redirect history not available HOT 2
- Add support for configuring default headers in AgentBuilder HOT 1
- Potential to modify ordering for IS_TEST in lib module HOT 1
- Change `send_json` `data` argument HOT 4
- Add `Error::as_response` HOT 3
- Middleware cannot modify query string parameters? HOT 2
- Decide what to do about rustls defaulting to aws-lc-rs instead of ring HOT 12
- Agent should be able to accept `http::Request` HOT 2
- bug: Can't set individual request timeouts HOT 2
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 ureq.