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

EventLoopContext#executeFromIO fails when executed by Netty GlobalEventExecutor #1657

Closed
vietj opened this issue Oct 1, 2016 · 1 comment
Milestone

Comments

@vietj
Copy link
Member

vietj commented Oct 1, 2016

When Netty uses its GlobalEventExecutor thread and propagates into Vertx, EventLoopContext#executeFromIO does not expect such thread and fails to execute the task:

for instance:

An exception was thrown by io.vertx.core.net.impl.ChannelProvider$$Lambda$62/807291119.operationComplete() 
java.lang.IllegalStateException: Uh oh! Event loop context executing with wrong thread! Expected null got Thread[globalEventExecutor-1-2,5,FailOnTimeoutGroup]
    at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:303)
    at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:190)
    at io.vertx.core.net.impl.NetClientImpl.failed(NetClientImpl.java:250)
    at io.vertx.core.net.impl.NetClientImpl.lambda$connect$5(NetClientImpl.java:225)
    at io.vertx.core.net.impl.ChannelProvider.lambda$connect$0(ChannelProvider.java:42)
    at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:514)
    at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:488)
    at io.netty.util.concurrent.DefaultPromise.access$000(DefaultPromise.java:34)
    at io.netty.util.concurrent.DefaultPromise$1.run(DefaultPromise.java:438)
    at io.netty.util.concurrent.GlobalEventExecutor$TaskRunner.run(GlobalEventExecutor.java:233)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
    at java.lang.Thread.run(Thread.java:745)

This can happen if the creation of a Bootstrap fails, in this case the promise is created with the GlobalEventExecutor (see AbstractBootstrap#initAndRegister())

@vietj
Copy link
Member Author

vietj commented Oct 1, 2016

Example of issue failing the creation of a channel:

io.netty.channel.ChannelException: Unable to create Channel from class class io.netty.channel.socket.nio.NioSocketChannel
    at io.netty.channel.ReflectiveChannelFactory.newChannel(ReflectiveChannelFactory.java:40)
    at io.netty.bootstrap.AbstractBootstrap.initAndRegister(AbstractBootstrap.java:319)
    at io.netty.bootstrap.Bootstrap.doResolveAndConnect(Bootstrap.java:163)
    at io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:145)
    at io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:126)
    at io.vertx.core.net.impl.ChannelProvider.connect(ChannelProvider.java:37)
    at io.vertx.core.net.impl.NetClientImpl.connect(NetClientImpl.java:230)
    at io.vertx.core.net.impl.NetClientImpl.connect(NetClientImpl.java:97)
    at io.vertx.redis.impl.RedisConnection.connect(RedisConnection.java:139)
    at io.vertx.redis.impl.RedisConnection.send(RedisConnection.java:237)
    at io.vertx.redis.impl.AbstractRedisClient.send(AbstractRedisClient.java:193)
    at io.vertx.redis.impl.AbstractRedisClient.sendString(AbstractRedisClient.java:86)
    at io.vertx.redis.impl.RedisClientImpl.ping(RedisClientImpl.java:2195)
    at io.vertx.test.redis.SomeTest.lambda$doTheTest$4(SomeTest.java:55)
    at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:324)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:440)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
    at java.lang.Thread.run(Thread.java:745)
Caused by: io.netty.channel.ChannelException: Failed to open a socket.
    at io.netty.channel.socket.nio.NioSocketChannel.newSocket(NioSocketChannel.java:64)
    at io.netty.channel.socket.nio.NioSocketChannel.<init>(NioSocketChannel.java:81)
    at io.netty.channel.socket.nio.NioSocketChannel.<init>(NioSocketChannel.java:74)
    at sun.reflect.GeneratedConstructorAccessor8.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at io.netty.channel.ReflectiveChannelFactory.newChannel(ReflectiveChannelFactory.java:38)
    ... 19 more
Caused by: java.net.SocketException: Too many open files in system
    at sun.nio.ch.Net.socket0(Native Method)
    at sun.nio.ch.Net.socket(Net.java:411)
    at sun.nio.ch.Net.socket(Net.java:404)
    at sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:105)
    at sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:60)
    at io.netty.channel.socket.nio.NioSocketChannel.newSocket(NioSocketChannel.java:62)
    ... 26 more

@vietj vietj closed this as completed Oct 16, 2018
@vietj vietj added this to the 3.6.0 milestone Oct 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant