mojira.dev
MC-33041

Dedicated server logs "java.io.IOException: The handle is invalid" on startup

Moderator Note

This error should not have any side effects and can be ignored (see section "Code analysis" for an explanation).
When starting the server from the command line no error is logged, for example:

java -Xmx1024M -Xms1024M -jar server.jar

The bug

When the dedicated server is started by double clicking the .jar file it logs the following error on startup:

1.13

[09:23:17 ERROR]: Exception handling console input
java.io.IOException: The handle is invalid
	at java.io.FileInputStream.readBytes(Native Method) ~[?:1.8.0_172]
	at java.io.FileInputStream.read(Unknown Source) ~[?:1.8.0_172]
	at java.io.BufferedInputStream.read1(Unknown Source) ~[?:1.8.0_172]
	at java.io.BufferedInputStream.read(Unknown Source) ~[?:1.8.0_172]
	at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) ~[?:1.8.0_172]
	at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[?:1.8.0_172]
	at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[?:1.8.0_172]
	at java.io.InputStreamReader.read(Unknown Source) ~[?:1.8.0_172]
	at java.io.BufferedReader.fill(Unknown Source) ~[?:1.8.0_172]
	at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.8.0_172]
	at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.8.0_172]
	at sn$2.run(SourceFile:107) [server.jar:?]

Code analysis

It seems that the reason for this is that the server can process commands provided from the command prompt (System.in) and independently from the JTextField. In case you do not start the server using the command prompt it still tries to read the input from it which is not possible. It appears that there is no way to prevent this because apparently System.in is not null by default and you cannot test if the readers can read without calling the reading methods and catching exceptions (which is the way it currently behaves).

As suggested in this StackOverflow answer the method InputStream.available() could be used at the start to detect if System.in is usable. If the .jar is not started from command line, then this method throws the exception as well. In this case a warning or an info message could be logged (including the exception?) and only the GUI input could be used.

Related issues

MC-35609 Server console handler/ERROR MC-36342 Only i Can Join My Server MC-36590 Server - java.io.IOException MC-36668 Server not loading properties MC-36697 Java error on server startup MC-36752 Error On Server Startup MC-40131 Server console handler/ERROR]: Exception handling console input MC-40430 java.io.IOException on SMP MC-41017 Minecraft 1.7.2 SERVER bug/error MC-42478 Minecraft 1.7.4 server issue MC-45729 Server console handler/ERROR MC-49648 [Server console handler/ERROR]: Exception handling console input java.io.IOException: The handle is invalid MC-51713 Starting server error for new servers MC-55725 help MC-55830 Multiplayer mode does not work MC-56620 Server displays Invalid Handle error in server logs - can't join MC-64977 Snapshot server not working MC-77320 Minecraft server 1.8.1.exe Giving - java.io.FileInputStream.readBytes(Native Method) MC-78860 My Server Console doesn't show anything! MC-79024 Handle is invalid error MC-80811 I am unable to connect to server from outside network MC-88222 Unique server bug I don't think has been solved MC-107292 Minecraft server reads java.io exception with on 1.10.2 server MC-112691 server.jar file crashes when opened MC-120831 Errors in logs when we starting a Vanilla server MC-127318 1.12.2 server not working MC-129135 Getting an error when trying to run a server MC-129220 Can join my server using localhost but no one can join using external IP MC-132936 error on java MC-161861 Server error, Exception handling console input MC-164050 IOException when starting server MC-181765 Error and Multiple Warnings in Java Edition Server MC-183285 Handle is invalid errors and server says "old" inside of minecraft but i am using the right version MC-265846 [Server console handler/ERROR]: Exception handling console input MC-277217 1.21.1 Server Exception errors MC-278072 I cannot joing my own server, and no one can

Attachments

Comments

migrated
[media][media][media]
migrated

"[09:23:17] [Server thread/INFO]: Starting minecraft server version 13w41b
[09:23:17] [Server console handler/ERROR]: Exception handling console input"

migrated

I'm getting this also in a standalone 1.7.2 server (executed as .jar file)

migrated

Same problem here. But connecting on server works well.

migrated

my 1.7.2 server was working fine until recently. I can log onto it but friends cant now. my server log looks same as reported by others. I would like to add that my Mozilla Foxfire recently updated to 25.0(x86en-US) and I also have Mozilla Maintenance Service that updated on the same day, Nov. 5th. I tried changing security on my browser but it had no effect.

migrated

I've been seeing this error in the logs since I updated to 1.7.2. I am using the minecraft_server.1.7.2.exe file to run the server on a Windows 7 64-bit machine with Java 1.7.0_45 64-bit. I can confirm that I am able to login successfully to the server, as are other users.

The way the error reads seems to be related to the display; the log and chat portion of the window remains blank the entire time the server is running, but the logs actively update. Running commands from the server window works as it should, and the normal feedback for running commands from the server window appears in the log. Other than the log (and chat) not displaying in the server GUI properly I have not seen any issues that seem to be related to this error.

I attached the server start-up leading into the error below for reference:

[07:33:43] [Server thread/INFO]: Starting minecraft server version 1.7.2
[07:33:43] [Server thread/INFO]: Loading properties
[07:33:43] [Server console handler/ERROR]: Exception handling console input
java.io.IOException: The handle is invalid
at java.io.FileInputStream.readBytes(Native Method) ~[?:1.7.0_45]
at java.io.FileInputStream.read(Unknown Source) ~[?:1.7.0_45]
at java.io.BufferedInputStream.read1(Unknown Source) ~[?:1.7.0_45]
at java.io.BufferedInputStream.read(Unknown Source) ~[?:1.7.0_45]
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) ~[?:1.7.0_45]
at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[?:1.7.0_45]
at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[?:1.7.0_45]
at java.io.InputStreamReader.read(Unknown Source) ~[?:1.7.0_45]
at java.io.BufferedReader.fill(Unknown Source) ~[?:1.7.0_45]
at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.7.0_45]
at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.7.0_45]
at ll.run(SourceFile:78) [minecraft_server.1.7.2.exe:?]

migrated

Still happening in 1.7.4

migrated

Please, any solution?

migrated

I still have this problem, Have a solution yet?

migrated

Snapshot 14w03b also affected.

Additional comment: Tested starting the server using a .bat file "Minecraft Server Startup.bat" with the Java command "java -Xmx1024M -Xms1024M -jar minecraft_server.14w03b.jar" and this resolved the error message because the console received input. When I used "Javaw" to start the server the error occurred.

migrated

Still in 1.7.8! I hope they'll fix it soon.

migrated

Still affecting 1.7.9 it seems!
Edit: I wonder if this is related to MC-38758

migrated

found that on my pc there was a old version of java under c\windows\jre... and when i remove this file from there my bat started working again

migrated

Still present in 14w28a

migrated

Still present in 14w30b

migrated

I've had this probem go away and start up again. I assume you have forge installed.
I just fixed it AGAIN. Extremely frustrating, since you should do a few things to ensure this is not killing your server.
First; it makes you a new world named "world" when it sees your other world that has grown too much in some way for the jvm to handle it. Before I get into that let's cover this;
Delete the file 'world' it made then rename your favorite world as 'world'. I just did that and fixed my problem....
but wait!
You have server properties file; use it. Delete all extras like port number and all that. Now start minecraft using a profile 1.7.2 for example without forge until your world loads up. It should show up, even amplified, and if not follow next steps either way;

Now you're ready to change Java memory settings. (windows 7)
3 things;
1; if you've not set the right path to 32 or 64 bit inside path from environmental variables under computer prop then do. Save your old line incase you screw that up. This tutorial you can find elsewhere I wont get into that.
2;set java virtual memory. Do this under control panel/ programs and features/java/ now under java control panel click java tab then view button. Since I have 8gb of ram (find out your ram # by going to start, right click on computer, properties : to see installed ram) then I am using 4gigs of it for java. CLICK TWICE FAST on the empty spot under RuntimePara...
Enter "-Xms4096m" without the quotation marks ofcourse , assuming you have 8g ram.
1024m if you have 2gigs and so on, since 1024 megabytes is equal to 1gigabyte.

3;(optional) Creative a startserver.bat file using notepad to start up java making double sure your server will be able to handle as much as possible. These numbers you can tweek later just like the other one. Make a text file obviously and enter this;
@echo off
java -Xmx6144M -Xms4096M -jar minecraft_server.1.7.2.jar gui

...that will give you a ram window of 4g to 6gigs instead of 1 to 1 or whatever, but restarting any server might not work eventually until you change the variable inside java virtual machine as stated earlier.
I MAY experience this problem again when I begin running mods in Forge since it takes more memory yet. Part of this problem is actually worse than you might think;
A system using an older hard drive or just one with years of use could have chip errors in the hard drive. They'll always work but do slow down for whatever reason. ..so getting an sshd or sshd hybrid will change things drastically for minecraft.
9.7.2014 mikefromspace utube

galaxy_2alex

Is this still a concern in the current Minecraft version 1.8.1 Prerelease 3 / Launcher version 1.5.3 or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

Also, make sure your Java is on 1.8 or higher.

migrated

It's been a while since I've had to deal with this, but ;
1; I recall fixing it by using an older version of Java since the new one would not allow any use of forge which so far I've only used to run optifine since the microsoft purchase pissed off a major contributor who wrote world edit. I do run 'no more cubes' once in a while for fun but my guy gets stuck on terrain no matter what with that.

2; Using optifine not possible in 1.8 which is slow as the frozen puke it is without optifine and I'm using a quad core i7 920 with 11g ram and a 1gig nvidia gtx260 video card. Even with optifine I need to go 30fps. Why the default ram is 1gig is beyond ridiculous. WHY CAN'T this be adjustable , I mean the script would be like 1 or 2 lines long to fix it !

Minecraft 1.8 is a joke. It's for 5 year olds who don't want amplified which is nuts. I have an amplified server setup. It would never work in 1.8 and I've already put too much work into it.

galaxy_2alex

Java 8 works fine for everything now. Wrong information on several ends. Also, this does not answer my question. Keeping it on "Awaiting Response".

migrated

I can confirm this, starting the server from the console did not fix it for me.

migrated

I just installed java 1.8 And I still have the problem.
Note that it doesn't happen on startup, but a couple of hours after the server started up.
I'm starting to wonder wether this is the same bug as I'm experiencing. This issue doesn't really have a good description so could someone tell me if the server is crashing for you as well? Here's the first part of my crash report.

error

[00:21:01] [Server console handler/ERROR]: Exception handling console input
java.io.IOException: Input/output error
        at java.io.FileInputStream.readBytes(Native Method) ~[?:1.8.0_25]
        at java.io.FileInputStream.read(FileInputStream.java:246) ~[?:1.8.0_25]
        at ...
        the rest is just the same as the other reports provided
migrated

I resolved this error for my 1.8.1pre3 / pre5 servers by disabled the Service for ReadyBoost on our Windows server machines. I noticed randomly windows was using 100% of HD resource read/write and was causing the server to "Run Behind" or just crashing I/O error.

4 days running since last maintenance & backup, with no crashing and minimal "Run Behind."

using startup bat:
"C:\Program Files\Java\jre1.8.0_25\bin\java.exe" -server -d64 -Xms3848M -Xmx3848M -jar minecraft_server.1.8.1-pre5.jar nogui

galaxy_2alex

Reopened.
@Jesper the End: I assigned the ticket to you, please change it to fit the issue better.

migrated

This certainly was an odd bug which I never could track down. Eventually I did end up reinstalling the entire windows7 o.s. and have been running on a rented server instead, but for a short time I did manage to fix the problem accidentally, although it was a line of code inside windows itself which is found under the most advanced settings after right clicking on "computer" to view properties, advanced tab, performance- settings. The issue may have been caused by using too much or too little ram in part, but I suspect it was simply bad ram. I was running 11g using 8 or 10 at the time on the setting with 2 different ddr3 ram brands installed. Later I removed 3 of the 1g old sticks and now using only 2 of the 4g sticks (newer) which doesn't error as it did before when running other programs like a chrome browser with multiple tabs open for example.

I'll be re-testing the server by next weekend I suspect and will see if I can't re-create this problem.

marcono1234

Confirmed for

  • 15w51b

It seems that the reason for this is that the server can process commands provided from the command prompt (System.in) and independently from the JTextField. In case you do not start the server using the command prompt it still tries to read the input from it which is not possible. It appears that there is no way to prevent this because apparently System.in is not null by default and you cannot test if the readers can read without calling the reading methods and catching exceptions (which is the way it currently behaves).

marcono1234

Could you please link from the description to the comment above

Avoma

Can confirm in 1.18.2.

Avoma

Can confirm in 1.19.

Avoma

Can confirm in 1.19.2 and 22w42a.

migrated

(Unassigned)

Confirmed

Platform

Low

Dedicated Server

console, server

Minecraft 13w39a, Minecraft 13w39b, Minecraft 13w41a, Minecraft 13w41b, Minecraft 13w42b, ..., 1.20.2, 24w12a, 1.21, 1.21.1, 1.21.3

Retrieved