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

Fix Portal.close for java_thread_pg_entry=allow mode #476

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions pljava/src/main/java/org/postgresql/pljava/internal/Portal.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004-2019 Tada AB and other contributors, as listed below.
* Copyright (c) 2004-2023 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
Expand All @@ -25,28 +25,29 @@
*/
public class Portal
{
/*
* Hold a reference to the Java ExecutionPlan object as long as we might be
* using it, just to make sure Java unreachability doesn't cause it to
* mop up its native plan state while the portal might still be using it.
*/
private ExecutionPlan m_plan;

private final State m_state;

Portal(DualState.Key cookie, long ro, long pointer, ExecutionPlan plan)
{
m_state = new State(cookie, this, ro, pointer);
m_plan = plan;
m_state = new State(cookie, this, ro, pointer, plan);
}

private static class State
extends DualState.SingleSPIcursorClose<Portal>
{
/*
* Hold a reference to the Java ExecutionPlan object as long as we might
* be using it, just to make sure Java unreachability doesn't cause it
* to mop up its native plan state while the portal might still want it.
*/
private ExecutionPlan m_plan;

private State(
DualState.Key cookie, Portal referent, long ro, long portal)
DualState.Key cookie, Portal referent, long ro, long portal,
ExecutionPlan plan)
{
super(cookie, referent, ro, portal);
m_plan = plan;
}

/**
Expand Down Expand Up @@ -76,6 +77,13 @@ private long getPortalPtr() throws SQLException
unpin();
}
}

@Override
protected void javaStateReleased(boolean nativeStateLive)
{
super.javaStateReleased(nativeStateLive);
m_plan = null;
}
}

/**
Expand All @@ -84,11 +92,7 @@ private long getPortalPtr() throws SQLException
*/
public void close()
{
doInPG(() ->
{
m_state.releaseFromJava();
m_plan = null;
});
m_state.releaseFromJava();
}

/**
Expand Down
Loading