softwaremill / elasticmq

In-memory message queue with an Amazon SQS-compatible interface. Runs stand-alone or embedded.
https://softwaremill.com/open-source/
Apache License 2.0
2.52k stars 193 forks source link

Actor System does not shut down when using `SQSRestServerBuilder#stopAndWait` - resulting in main process hanging indefinitely #860

Closed mgr32 closed 1 year ago

mgr32 commented 1 year ago

Description

When using SQSRestServerBuilder directly, stopAndWait method does not shutdown the Actor System, resulting in main process hanging indefinitely.

The following code hangs indefinitely since 1.0.0 (finishing correctly in 0.15.8):

public static void main(String[] args) {
   var sqsRestServer = SQSRestServerBuilder.withDynamicPort().start();
   sqsRestServer.waitUntilStarted();
   sqsRestServer.stopAndWait();
}

Minimal reproducible example (Java): https://github.com/mgr32/elasticmq-stopandwait-issue

Expected results

The above code should finish, in the same way as it worked in 0.15.8.

Details

Last version working ok: 0.15.8 First version where the issue occurs: 1.0.0 Last version checked where the issue occurs: 1.4.2

Commit that probably introduced the issue: https://github.com/softwaremill/elasticmq/commit/e49a1d2408f47cff7c1f6543659a0b92372756fb

Workaround

To workaround the issue, you can create and terminate ActorSystem manually:

public static void main(String[] args) throws Exception {
        var actorSystem = ActorSystem.apply("elasticmq");
        var sqsRestServer = SQSRestServerBuilder.withActorSystem(actorSystem).withDynamicPort().start();
        sqsRestServer.waitUntilStarted();
        sqsRestServer.stopAndWait();
        Await.result(actorSystem.terminate(), FiniteDuration.apply(1, TimeUnit.MINUTES));
    }
micossow commented 1 year ago

Thanks for reporting the issue! It should be fixed in https://github.com/softwaremill/elasticmq/releases/tag/v1.4.3

mgr32 commented 1 year ago

Thank you @micossow for such a quick fix, it helped :+1: