ipfs-shipyard / java-ipfs-http-client

A Java implementation of the HTTP IPFS API
MIT License
538 stars 243 forks source link

Implement HTTP client side timeout #147

Closed gjeanmart closed 4 years ago

gjeanmart commented 4 years ago

The purpose of this feature is to implement an optional HTTP client side timeout using HttpURLConnection.setReadTimeout(int timeout) because the API Server doesn't provide any timeout mechanism and when java-ipfs-http-client does IPFS.cat(multihash) but the hash cannot be found on the IPFS network, the call hangs forever (or until found). This is usually quite risky and bad practice for a client to block threads like that.

So the idea is to configure a timeout (in ms) to prevent this:

IPFS ipfs = new IPFS(new MultiAddress("/ip4/127.0.0.1/tcp/5001")).timeout(1000)
gjeanmart commented 4 years ago

PS: A bunch of tests fail but it seems to be the case on master branch as well so I didn't bother fixing it and might give a try in another PR!

ianopolous commented 4 years ago

Thanks! This is a nice improvement