Comments (5)
Hi @John-Nagle!
ureq does use set_nonblocking()
temporarily when it wants to check that a pooled connection to a server is still fresh. The way it does it is:
set_nonblocking(true)
- Try read.
set_nonblocking(false)
The idea is that in the happy path, the read should result in a EWOULDBLOCK indicating the connection is still open and can be used. A closed connection would give us another error, and if we manage to read any bytes, the server sent stuff we didn't expect (meaning it's best to close since otherwise we risk request smuggling etc).
I wonder if what you observe maybe has something to do with this?
from ureq.
Possibly. Ureq can usefully use nonblocking I/O at some points. But status EWOULDBLOCK should never make it out to the caller.
For now, I turned on a retry loop which, on any error, waits 1 second and tries the connection again, for 5 tries. That will probably work around intermittent errors.
from ureq.
from ureq.
pub fn fetch_capabilities(
client: &HttpClient,
cap_url: &str,
keys: &[&str],
) -> Result<HashMap<String, String>, Error> {
const RETRIES: usize = 0; // try this many times
// Construct request in LLSD format
let query = compose_query(keys).with_context(|| {
format!(
"Composing query for capabilities {:?} from {}",
keys, cap_url
)
})?;
// Retry query. Especially on Open Simulator, tries can fail.
// Documentation says that firewall/CDN problems can cause transient 5xx errors.
let mut try_count = 0;
let reply = loop {
log::info!("Capability query to {}: {}", cap_url, query);
// Send HTTP request and block.
let http_result = client
.agent
.post(cap_url)
////.set("Content-Type", "text/xml") // "text/xml; charset=utf-8" is rejected by SL server
.set("Content-Type", "application/llsd+xml") // "text/xml; charset=utf-8" is rejected by SL server
.send_string(&query)
.map_err(anyhow::Error::msg)
.with_context(|| format!("Fetching capabilities {:?} from {}", keys, cap_url));
// Analyze result
match http_result {
Ok(reply) => break reply, // good
Err(e) => {
log::error!(
"Error reading capability {}, try {}: {:?}",
cap_url,
try_count,
e
);
try_count += 1;
if try_count > RETRIES {
return Err(e);
}
std::thread::sleep(std::time::Duration::from_millis(1000)); // wait before retry
}
}
};
...
This was running with RETRIES=0, so any failure was fatal. It's now running with RETRIES=5.
This is deep inside a metaverse client for Second Life/Open Simulator. The servers provide a URL which is queried for some internal data. This particular code is executed a few times per minute, maximum. As the player moves around, this is part of the system which attaches new regions. So it's not heavy traffic. The server side is 20 year old code, and may be misbehaving. The client code above has been unchanged for the last year.
from ureq.
Closing since we're moving to ureq 3.x. The behavior is changing.
from ureq.
Related Issues (20)
- 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 2
- 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 13
- Agent should be able to accept `http::Request` HOT 3
- bug: Can't set individual request timeouts HOT 2
- rustls upgrade in 2.10 is a breaking change? HOT 18
- Include lib.rs docs from README.md HOT 1
- any plans regarding ureq 2.10.1 release HOT 2
- Feature request: Automatically close connections that haven't been used for a while HOT 11
- 3.x regression: casing of header names is not preserved HOT 5
- 3.x make timeouts configurable per request
- Binary data iscorrupted - ureq is no drop in replacement for reqwwest - perhaps it does not work at all? HOT 4
- ureq 3.x improve resolver HOT 1
- ureq 3.x throughput test HOT 2
- ureq 3.x Panic Incorrect state: Cleanup
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.