(note: replaces https://github.com/FasterXML/jackson-databind/issues/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 https://github.com/FasterXML/jackson-databind/issues/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.

Comment From: cowtowncoder

Is #1461 same as this one? Seems related at least.

Comment From: pjfanning

@cowtowncoder can I make a left field suggestion? Can we deprecate the API methods that take URL inputs and remove them from 3.x. Jackson libs have enough to worry about and having users ask us to support HTTP connections and do connection pooling - that says to me that we are offering a convenience feature that we don't really need. Let users manage their own URL lookups and get InputStreams that they pass to Jackson. They can worry about all the URL stuff like error handling, connection pooling and validating the URLs are not dangerous.