Skip to content

Improve handling of URL-backed InputStreams, closing #803

@cowtowncoder

Description

@cowtowncoder

(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions