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

PostgreSQL processes remain running after JabRef crashes or is forcefully terminated #12844

Open
2 tasks done
ungerts opened this issue Mar 28, 2025 · 9 comments
Open
2 tasks done

Comments

@ungerts
Copy link
Contributor

ungerts commented Mar 28, 2025

JabRef version

Latest development branch build (please note build date below)

Operating system

Windows

Details on version and operating system

Windows 10

Checked with the latest development build (copy version output from About dialog)

  • I made a backup of my libraries before testing the latest development version.
  • I have tested the latest development version and the problem persists

Steps to reproduce the behaviour

When JabRef crashes or is forcefully terminated (e.g., via kill -9 or Task Manager), associated PostgreSQL processes often remain running. These orphaned processes continue to consume system resources unnecessarily.

Steps to Reproduce

  1. Start JabRef with a PostgreSQL backend.
  2. Forcefully terminate JabRef (e.g., using kill -9 or Task Manager).
  3. Open Task Manager (Windows) or use ps on Linux/macOS.
  4. Observe that multiple PostgreSQL Server processes are still running.

Expected Behavior

All PostgreSQL-related processes spawned by JabRef should terminate when JabRef is unexpectedly closed.

Actual Behavior

PostgreSQL processes persist after JabRef exits unexpectedly, leading to orphaned background processes.

Appendix

Screenshot

PostgreSQL orphaned processes

Screenshot shows several idle PostgreSQL Server processes still running after JabRef was terminated.

@github-project-automation github-project-automation bot moved this to Normal priority in Prioritization Mar 28, 2025
@Siedlerchr
Copy link
Member

Sigkill cannot be caught, but it would probably make sense to add a shutdown hook to ensure running instances are closed when sigterm occurs

@subhramit
Copy link
Member

subhramit commented Mar 28, 2025

I have faced this too (noticed this yesterday). Every time I close and re-run JabRef (when running via IntelliJ), my task manager shows the old Postgres instance running. On running a new JabRef session again, a new Postgres session is also launched. After 5-6 trials, I was wondering why my system was lagging so much, then checked the task manager which had 6 running postgres instances.

Edit - what I meant was another implication of this is lag during development.

Edit - more details:
1st run: 1 background process, 6 instances:

Image

Second run using IntelliJ reload:

Image

Now there are 2 background processes, 12 instances:

Image

All of them on CPU 00:

Image

And so on...

@subhramit subhramit moved this from Normal priority to High priority in Prioritization Mar 28, 2025
@subhramit subhramit added this to the 6.0-beta milestone Mar 28, 2025
@Siedlerchr
Copy link
Member

Siedlerchr commented Mar 28, 2025

@subhramit
Copy link
Member

Tried with:

public class Launcher {

    public static void main(String[] args) {
       ...

        PostgreServer postgreServer = new PostgreServer();
        Injector.setModelOrService(PostgreServer.class, postgreServer);
        
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            if (postgreServer != null) {
                try {
                    postgreServer.shutdown();
                    System.out.println("PostgreServer successfully shut down");
                } catch (Exception e) {
                    System.err.println("Error shutting down PostgreServer: " + e.getMessage());
                }
            }
        }));

        JabRefGUI.setup(uiCommands, preferences, fileUpdateMonitor);
        JabRefGUI.launch(JabRefGUI.class, args);
    }
}

Didn't work

@subhramit
Copy link
Member

Tried with:
...
Didn't work

On checking logs, neither the try nor the catch is executed. On reading more, it appears that it's because there is no way to reliably execute code in case of a SIGKILL (the shutdownhook helps in case of SIGTERM and SIGINT).

@Siedlerchr
Copy link
Member

Siedlerchr commented Mar 28, 2025 via email

@subhramit
Copy link
Member

Hmm...so is this issue unsolvable from the perspective of shutdown it seems..

@koppor
Copy link
Member

koppor commented Mar 29, 2025

Hmm...so is this issue unsolvable from the perspective of shutdown it seems..

Idea for workaround: On start of new JabRef instance, old postgres (from JabRef) could be re-used (or killed)

@ungerts
Copy link
Contributor Author

ungerts commented Mar 29, 2025

Idea for workaround: On start of new JabRef instance, old postgres (from JabRef) could be re-used (or killed)

To me, this feels a bit like performing "magic" on the user's machine. Implementing such behavior is likely to be complex and error-prone.

  • PostgreSQL ports are allocated automatically. As a result, the application would need to either:

    • Detect the port currently in use at runtime, or
    • Persist the assigned port on first launch and reuse it upon restart.
  • Multiple PostgreSQL instances might be running on the user's system:

    • Some could be installed manually by the user.
    • Others might be leftover (or orphaned) instances from previous JabRef sessions.

This leads to a critical question: Which instance should JabRef attempt to reuse - or safely shut down?

@subhramit subhramit modified the milestones: 6.0-beta, 6.0 Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: High priority
Development

No branches or pull requests

4 participants