Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Need an API to set socket timeout for URLConnection that SAAJ uses #70

Open
glassfishrobot opened this issue Aug 30, 2012 · 11 comments
Open

Comments

@glassfishrobot
Copy link
Contributor

SAAJ uses URLConnection internally to make SOAP call. There is no way to set timeout for connection.call. This result is locked thread for over 10 mins.

From JDK 1.5 onwards URLConnection support setting of timeout for socket connection.

SAAJ lib should implement this timeout and provide an API to set the value of timeout.

Environment

linux

Affected Versions

[1.3]

@glassfishrobot
Copy link
Contributor Author

Reported by neoneo008

@glassfishrobot
Copy link
Contributor Author

Was assigned to super_glassfish

@glassfishrobot
Copy link
Contributor Author

neoneo008 said:
Can we all discuss & get closer on this issue. It causing lot thread lock problem in our env whenever the device doesn't respond due to heavy load.

@glassfishrobot
Copy link
Contributor Author

gagordon said:
I don't see a way in the standard SAAJ API to accomplish this. To add a new API would require a spec change, which is not trivial. The best I can offer now is a SAAJ-impl specific system property, or as you may be implying, a "back-door" API into the com.sun packages which is not a good idea for several reasons, and is not an approach that should be pursued IMO.

That said, to quote one article I found on Java socket timeouts, "Keeping [an] unused TCP connection open for [a] long time without any traffic isn't that trivial. Many firewalls/routers close the unused ports after some timeout."

So given this, I am not sure whether your service design might benefit from being asynchronous if it is prone to timeout. It is my personal experience in dealing with these kinds of timeout issues that increasing the timeout often doesn't adequately resolve the issue due problems such as those mentioned above.

@glassfishrobot
Copy link
Contributor Author

neoneo008 said:
Completely agreed with you. We need a API spec update to fix this problem which is not trivial & will have to wait until the next major release.

Most of the places where I have encountered this issue was where the complete network of legacy devices & servers are in the same DMZ zone. This takes out routers & firewalls out the the communication network.

Service design cannot be changed to asynchronous due to the nature of the third party systems.

In such scenarios, for now at least we could have a workaround or a back-door API or a -d JAVA OPTION to temporarily fix this issue until the next major release & spec update.

We could later rollback this back-door fix.

@glassfishrobot
Copy link
Contributor Author

gagordon said:
@neoneo008: As I had mentioned, adding a new public API to an internal class isn't a good idea, so I'd consider a system property, which would effectively be globally on or off, and assumes the currently installed security manager in your environment will allow setting or reading of system properties, else a SecurityException would be thrown. Are you interested in adding a property for connection timeout, read timeout, or both?

@glassfishrobot
Copy link
Contributor Author

gagordon said:
After doing further research, I believe it is already possible to set the connection and read timeouts in standard Java by defining your own URLStreamHandler and passing it as the third arg to the URL constructor:

public URL(URL context, String spec, URLStreamHandler handler)

The URLStreamHandler would override its abstract and protected method openConnection(URL) on the URL it creates from the other parameters, thereby getting a URLConnection. The read and connect timeout parameters can then be set on the URLConnection created in openConnection() before the method returns.

Therefore, it is best to not change anything in the current implementation and we can address the API in release 1.4.

@glassfishrobot
Copy link
Contributor Author

neoneo008 said:
Can you please provide an insight on rough/approx timelines for 1.4 release?
This would help us to plan accordingly like coming up with automated workaround to handle such scenarios in health monitor.

@glassfishrobot
Copy link
Contributor Author

gagordon said:
@neoneo008: SAAJ 1.4 will not be in JDK 8, but the SAAJ API and reference implementation will likely need some redesign when it is adapted to work with JDK 9.

@glassfishrobot
Copy link
Contributor Author

This issue was imported from java.net JIRA SAAJ-70

@phansson
Copy link

phansson commented Sep 27, 2017

Is setting system properties

sun.net.client.defaultConnectTimeout
sun.net.client.defaultReadTimeout

a possible workaround? These are the global defaults for URLConnection so they will affect more than just SAAJ, but this may still be acceptable.

Documentation: Networking Properties.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants