mojira.dev
MC-133063

JVM Crash when connecting to an unreachable server (instead of showing error message)

Update 1.13: JVM crashes in lwjgl_opengl.dll+0xe92d when logging into REALMS MC-134199


Minecraft crashes when trying to connect to an unreachable server

Steps to reproduce

  • Have a known unreachable server in your multiplayer server list, e.g. localhost:25566

  • Try to connect to that server

  • Crash instead of showing error message

1.13-pre6

1.13-pre6

[17:48:24] [Client thread/INFO]: Connecting to localhost, 25565
[17:48:25] [Server Connector #1/ERROR]: Couldn't connect to server
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/127.0.0.1:25565
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[?:1.8.0_51]
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[?:1.8.0_51]
	at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:325) ~[netty-all-4.1.25.Final.jar:4.1.25.Final]
	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340) ~[netty-all-4.1.25.Final.jar:4.1.25.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:635) ~[netty-all-4.1.25.Final.jar:4.1.25.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:582) ~[netty-all-4.1.25.Final.jar:4.1.25.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499) ~[netty-all-4.1.25.Final.jar:4.1.25.Final]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:461) ~[netty-all-4.1.25.Final.jar:4.1.25.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) ~[netty-all-4.1.25.Final.jar:4.1.25.Final]
	at java.lang.Thread.run(Thread.java:745) ~[?:1.8.0_51]
Caused by: java.net.ConnectException: Connection refused: no further information
	... 10 more

Game terminates and throws JVM stack trace

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 6075  org.lwjgl.opengl.GL11.glBindTexture(II)V (0 bytes) @ 0x0000000003544cc4 [0x0000000003544c80+0x44]
J 6476 C2 dci.h()V (10 bytes) @ 0x00000000033c175c [0x00000000033c16e0+0x7c]
j  che.a(Lchf;)Lchg;+32
j  chd.a(Lchf;)Lchg;+31
j  chd.b(C)Lchi;+61
J 6117 C2 chd.a(C)Lchi; (64 bytes) @ 0x0000000003d51710 [0x0000000003d516a0+0x70]
J 6657 C1 cfj.e(Ljava/lang/String;I)I (246 bytes) @ 0x00000000032e6e6c [0x00000000032e6540+0x92c]
J 6673 C1 cfj.d(Ljava/lang/String;I)Ljava/lang/String; (155 bytes) @ 0x0000000003a5be34 [0x0000000003a5bc20+0x214]
j  cfj.c(Ljava/lang/String;I)Ljava/util/List;+3
j  cik.c()V+21
j  cix.a(Lces;II)V+50
j  ces.a(Lcix;)V+129
j  cie$1.run()V+337
v  ~StubRoutines::call_stub

1.12.2

1.12.2

20:27:18	bkr	Connecting to localhost, 25566
20:27:19	bkr	Couldn't connect to server
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/127.0.0.1:25566
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
	at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:352)
	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:612)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:559)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:476)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused: no further information
	... 10 more

Game keeps running, shows error message

Linked issues

Attachments

Comments 6

Please attach the server.log of the same time as the log above.

By the server is offline I mean that the server isn't running

Got it.
And confirmed.

This is probably the same issue that was described in https://github.com/LWJGL/lwjgl3/issues/304 except with glBindTexture instead of glGenTextures:

Current thread (0x000000001e6d2000):  JavaThread "Server Connector #1" [_thread_in_native, id=6904, stack(0x0000000034930000,0x0000000034a30000)]

siginfo: ExceptionCode=0xc0000005, reading address 0x00000000000001c0

and

Stack: [0x0000000034930000,0x0000000034a30000],  sp=0x0000000034a2e988,  free space=1018k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [lwjgl_opengl.dll+0xe92d]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 6075  org.lwjgl.opengl.GL11.glBindTexture(II)V (0 bytes) @ 0x0000000003544cc4 [0x0000000003544c80+0x44]
J 6476 C2 dci.h()V (10 bytes) @ 0x00000000033c175c [0x00000000033c16e0+0x7c]
j  che.a(Lchf;)Lchg;+32
j  chd.a(Lchf;)Lchg;+31
j  chd.b(C)Lchi;+61
J 6117 C2 chd.a(C)Lchi; (64 bytes) @ 0x0000000003d51710 [0x0000000003d516a0+0x70]
J 6657 C1 cfj.e(Ljava/lang/String;I)I (246 bytes) @ 0x00000000032e6e6c [0x00000000032e6540+0x92c]
J 6673 C1 cfj.d(Ljava/lang/String;I)Ljava/lang/String; (155 bytes) @ 0x0000000003a5be34 [0x0000000003a5bc20+0x214]
j  cfj.c(Ljava/lang/String;I)Ljava/util/List;+3
j  cik.c()V+21
j  cix.a(Lces;II)V+50
j  ces.a(Lcix;)V+129
j  cie$1.run()V+337
v  ~StubRoutines::call_stub

In particular, note "reading address 0x00000000000001c0", and that it's the "Server Connector" thread. Per this comment on the ticket (this is probably case a there):

LWJGL uses a thread-local array of pointers to call OpenGL functions. f00 is the glGenTextures offset in that array. The crashes you're seeing mean that there is no OpenGL context current in the current thread when the function is called (NULL + f00 == 0x0000000000000f00).

Users are not expected to know this of course, but another hint is that the crash happens in lwjgl_opengl.dll/so, rather than in the OpenGL driver. This can only happen if a) no context is current or b) lwjgl-opengl.jar and the corresponding lwjgl_opengl shared library come from different LWJGL releases. LWJGL does not do anything in JNI code except forward the call to the native library.

Such application bugs are common and indeed LWJGL does not throw a useful exception in this case. It did in previous releases, but a trade-off has been made; the current implementation prefers optimal performance over debugging utility.

This is basically the same issue as MC-111755: displayGuiScreen is called from the wrong thread when failing to connect to the server. However, my guess is that the newly added font code is now causing GL code to be called in initGui, making a crash happen 100% of the time (instead of requiring a race condition).

The fix for this is the same as the fix for that: schedule a task to display the GUI (i.e. replace mc.displayGuiScreen(new GuiDisconnected(...)) with mc.addScheduledTask(() -> mc.displayGuiScreen(new GuiDisconnected(...)). It would also make sense to add a check for wrong-thread calls in displayGuiScreen to catch similar mistakes.

Dominik Remes

Erik Broes

Confirmed

lwjgl, ttf

Minecraft 1.13-pre6

Minecraft 1.13-pre7

Retrieved