Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of URL-backed InputStreams, closing #803

Open
cowtowncoder opened this issue Jul 31, 2022 · 0 comments
Open

Improve handling of URL-backed InputStreams, closing #803

cowtowncoder opened this issue Jul 31, 2022 · 0 comments

Comments

@cowtowncoder
Copy link
Member

(note: replaces FasterXML/jackson-databind#3520)

It looks like JDK's HttpURLConnection has unfortunate handling of some error cases, leading to leakage of not-fully-closed HTTP connections under some error conditions. See FasterXML/jackson-databind#3455 for details.

It seems like we might be able to handle some of those cases if we could do something like:

URLConnection connection = new URL(url).openConnection();
try (InputStream stream = connection.getInputStream()) {
  // parse JSON
} finally {
  // java.net.HttpURLConnection.HttpURLConnection
  if (connection instanceof HttpURLConnection) {
    ((HttpURLConnection) connection).disconnect();
  }
}

(as suggested by @fxha -- thanks!)

But due to separation of concerns, this cannot (or should not) be done in databind. Instead we could wrap URL-backed InputStream in these cases, delegated all calls except for close(): and in close() we would do disconnect.

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

No branches or pull requests

1 participant