Giter Site home page Giter Site logo

Comments (3)

jsha avatar jsha commented on May 30, 2024 1

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.

johan-bjareholt avatar johan-bjareholt commented on May 30, 2024

Sorry for the late reply, been busy. Will try to create a minimal example.

from ureq.

johan-bjareholt avatar johan-bjareholt commented on May 30, 2024

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)

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.