Skip to content

Commit

Permalink
fix: make sure to avoid double close of result sets
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Sep 3, 2024
1 parent 582ba6e commit aaf84ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class OLocalResultSet implements OResultSet {
private OResultSet lastFetch = null;
private final OInternalExecutionPlan executionPlan;
private boolean finished = false;

long totalExecutionTime = 0;
long startTime = 0;
private long totalExecutionTime = 0;
private long startTime = 0;
private boolean closed = false;

public OLocalResultSet(OInternalExecutionPlan executionPlan) {
this.executionPlan = executionPlan;
Expand All @@ -47,7 +47,7 @@ private boolean fetchNext() {

@Override
public boolean hasNext() {
if (finished) {
if (finished || closed) {
return false;
}
if (lastFetch.hasNext()) {
Expand Down Expand Up @@ -102,7 +102,10 @@ public long getStartTime() {

@Override
public void close() {
executionPlan.close();
if (!closed) {
executionPlan.close();
closed = true;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class OLocalResultSetLifecycleDecorator implements OResultSet {
private OResultSet entity;
private List<OQueryLifecycleListener> lifecycleListeners = new ArrayList<>();
private String queryId;

private boolean hasNextPage;
private boolean closed = false;

public OLocalResultSetLifecycleDecorator(OResultSet entity) {
this.entity = entity;
Expand All @@ -38,11 +38,15 @@ public void addLifecycleListener(OQueryLifecycleListener db) {

@Override
public boolean hasNext() {
boolean hasNext = entity.hasNext();
if (!hasNext) {
close();
if (closed) {
return false;
} else {
boolean hasNext = entity.hasNext();
if (!hasNext) {
close();
}
return hasNext;
}
return hasNext;
}

@Override
Expand All @@ -56,9 +60,12 @@ public OResult next() {

@Override
public void close() {
entity.close();
this.lifecycleListeners.forEach(x -> x.queryClosed(this.getQueryId()));
this.lifecycleListeners.clear();
if (!closed) {
entity.close();
this.lifecycleListeners.forEach(x -> x.queryClosed(this.getQueryId()));
this.lifecycleListeners.clear();
closed = true;
}
}

@Override
Expand Down

0 comments on commit aaf84ba

Please sign in to comment.