FasterXML / FasterXML/jackson-dataformats-binary

IonFactory may leave initial IOContext unreleased after parser construction

Open
#792 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
347
Forks
156
Avg merge
3d 3h
Merged PRs (30d)
22

Description

## Summary

While working on #780, I was tracing the resource lifecycle in the `IonFactory` parser construction paths and noticed a separate issue with `IOContext` ownership.

For `File`/`Path` parser construction, `IonFactory` first creates an `IOContext` for the original input and uses it during input decoration.

Later, `_createParser(..., InputStream)` creates an `IonReader` and replaces the original context with a new one:

```java
IonReader ion = _system.newReader(in);
ioCtxt = _createContext(_createContentReference(ion), true);
````

I checked #325, and the second `IOContext` appears to be intentional: it makes the `IonReader` the resource managed by the parser, so closing the parser also closes the `IonReader`.

However, the first `IOContext` has already acquired its own `BufferRecycler`. Once `ioCtxt` is replaced, the resulting `IonParser` only retains the second context, and the first context no longer appears to have an owner responsible for releasing it.

The lifecycle looks roughly like:

```text
initial IOContext

input decoration

IonReader created

second IOContext created for IonReader

IonParser owns second IOContext

parser.close()

second IOContext released
initial IOContext remains unreleased
```

Unlike #780, this does not appear to be limited to failed construction. The initial `IOContext` may remain unreleased even when parser construction succeeds and the parser is later closed normally.

This may also affect other parser overloads that create an initial `IOContext` before going through the same `IonReader` construction path.

## Expected behavior

When ownership moves from the initial input context to the `IonReader`-based context, the initial `IOContext` should also have its lifecycle completed so that its `BufferRecycler` lease is returned, while preserving the intended resource management of the `IonReader`.

I noticed this while addressing #780, but since this also affects successful parser construction, I think it is better handled as a separate lifecycle issue.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.