Datagram socket still lives across JUnit tests using VertxUnitRunner

124 views
Skip to first unread message

Eimi Okuno

unread,
Aug 9, 2017, 8:35:27 AM8/9/17
to vert.x
Overview

I am running JUnit tests on two classes. The WebVerticle class deploys a verticle and instantiates a DatagramSocket class by passing the verticle's reference. The DatagramSocket class then uses the verticle to deploy a datagram socket. When I run the unit tests for these classes, I can see that the tests have passed, but there is an exception with the error message: "Failed to submit a listener notification task. Event loop shut down?". The Finalizer is unable to close a datagram socket, due to an event loop being shut down prematurely, and no listeners can be notified.

Problem

The full error trace:

Aug 09, 2017 10:24:28 AM io.netty.util.concurrent.DefaultPromise safeExecute
SEVERE
: Failed to submit a listener notification task. Event loop shut down?
java
.util.concurrent.RejectedExecutionException: event executor terminated
 at io
.netty.util.concurrent.SingleThreadEventExecutor.reject(SingleThreadEventExecutor.java:821)
 at io
.netty.util.concurrent.SingleThreadEventExecutor.offerTask(SingleThreadEventExecutor.java:327)
 at io
.netty.util.concurrent.SingleThreadEventExecutor.addTask(SingleThreadEventExecutor.java:320)
 at io
.netty.util.concurrent.SingleThreadEventExecutor.execute(SingleThreadEventExecutor.java:746)
 at io
.netty.util.concurrent.DefaultPromise.safeExecute(DefaultPromise.java:760)
 at io
.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:428)
 at io
.netty.util.concurrent.DefaultPromise.setFailure(DefaultPromise.java:113)
 at io
.netty.channel.DefaultChannelPromise.setFailure(DefaultChannelPromise.java:87)
 at io
.netty.channel.AbstractChannelHandlerContext.safeExecute(AbstractChannelHandlerContext.java:1011)
 at io
.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:611)
 at io
.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:466)
 at io
.netty.channel.DefaultChannelPipeline.close(DefaultChannelPipeline.java:964)
 at io
.netty.channel.AbstractChannel.close(AbstractChannel.java:234)
 at io
.vertx.core.net.impl.ConnectionBase.close(ConnectionBase.java:121)
 at io
.vertx.core.datagram.impl.DatagramSocketImpl.finalize(DatagramSocketImpl.java:341)
 at java
.lang.System$2.invokeFinalize(System.java:1270)
 at java
.lang.ref.Finalizer.runFinalizer(Finalizer.java:98)
 at java
.lang.ref.Finalizer.access$100(Finalizer.java:34)
 at java
.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:210)



Symptoms + Analysis

The above error messages always occurs right after:

Running testCleanUp.DataSocketTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.484 sec - in testCleanUp.DataSocketTest
Running testCleanUp.WebVerticleTest

Running each test on its own shows no problems. The problem is only reproducible in this order: DataSocketDeployer, WebVerticle.

Initially, I thought that the socket was not being closed in time for the second test to run. The theory was that the reference of the data socket survived for sometime, even after the vertx.close() was initialised, causing some race conditions to occur.
Ensuring that the datagram socket was closed, there were no datagrams being sent, and making the thread sleep for a fairly long time in between the tests did not solve the issue.


Code
I have put together a reproducer - Please see the attached code.



If anyone could help, would be much appreciated!

pom.xml
DataSocket.java
WebVerticle.java
DataSocketTest.java
WebVerticleTest.java

Eimi Okuno

unread,
Aug 9, 2017, 9:00:00 AM8/9/17
to vert.x
The vertx that I use here is actually the newest 3.4.2 and not 3.4.1. Forgot to update the pom here!

Julien Viet

unread,
Aug 9, 2017, 9:13:04 AM8/9/17
to ve...@googlegroups.com
can you put that together in a small zip project or a github project ?

thanks

Julien

-- 
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/27f68152-af3d-4f91-b505-e9b720ab91ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eimi Okuno

unread,
Aug 9, 2017, 9:40:27 AM8/9/17
to vert.x
Hi Julien,

Thanks for the fast reply.
I've uploaded the code and attached a Readme, which is essentially whatever mentioned above.

Thanks.

Eimi

Eimi Okuno

unread,
Aug 9, 2017, 9:40:46 AM8/9/17
to vert.x

utel

unread,
Aug 21, 2017, 5:50:21 AM8/21/17
to vert.x
Hello,

I'm also getting the same type of error described here.
Does anyone in the group have an idea of whether there's a reliable way to shutdown resources cleanly?
I've also tried the reproducer supplied by the OP (https://github.com/emettely/testCleanUp) and can see the error there when running:
 mvn clean test

Thanks!

On Wednesday, August 9, 2017 at 2:40:46 PM UTC+1, Eimi Okuno wrote:
https://github.com/emettely/testCleanUp

Julien Viet

unread,
Aug 21, 2017, 1:03:16 PM8/21/17
to ve...@googlegroups.com
Hi,

I think in your case the DatagramSocket is properly closed by your code and the finalizer closes the socket a second time (so the stack trace is just a cosmetic side effect)

I tried with 3.5.0.Beta1 and it works fine as this code was partly rewritten and now only closes the socket if it’s open.

Julien

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.

Eimi Okuno

unread,
Aug 23, 2017, 5:56:16 AM8/23/17
to vert.x
Hi Julien,

Thanks for letting me know - will look into upgrading vertx, once a newer stable version comes out.
Many thanks,

Eimi
Reply all
Reply to author
Forward
0 new messages