gwtgwt-maven-plugin

Encountering bindException when running CodeServer


I maintain a GWT multi-module maven project dated back to the good old golden GWT-days. We were able to debug the GWT application till now relying on classic dev mode but now due to security concerns , we are trying to setup our dev environment (Eclipse IDE) to use Super Dev Mode.

But when it comes to development, hence running Super Dev Mode, we've been encountering a bindException( ports clashing) when we try to start CodeServer.

Please find below the configs used and what exceptions we encountered:

Super Dev Mode (launcher configs)

main class: com.google.gwt.dev.DevMode
-logLevel INFO -port 8889 -remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -codeServerPort 9997 -war {directory to web app} -workDir {work directory} {module}

Observation:

Super Dev Mode starts correctly and has been configured to run on port 9997:

http://127.0.0.1:8889/app.html

Next step is I tried to launch the CodeServer:

CodeServer (launcher configs)

main class: com.google.gwt.dev.codeserver.CodeServer
-logLevel INFO -port 9876 -workDir {work directory} -src src/ {module}

Observation:

The following exception is obtained and subsequently, codeserver is never started.

[main] WARN org.eclipse.jetty.util.component.AbstractLifeCycle - FAILED ServerConnector@5c168f93{HTTP/1.1}{127.0.0.1:9876}: java.net.BindException: Address already in use java.net.BindException: Address already in use

From there, no other clues (error-out or stacktraces) are visible to me. After spending three days on the issue so far, seems we are hitting a wall here.

My queries are the following:

  1. Definitely the ports are clashing between CodeServer and Super Dev Mode. How can the CodeServer and Super Dev Mode be configured to work on same ports?
  2. when starting up the Super Dev Mode, does it internally also launches a codeserver instance on port 9876 by default.

Love to share my findings if you face similar hurdles.

Best, Javed

p.s.: In a Java 8 environment, I am able to use GWT 2.9.0 and it's Super Dev Mode (via Eclipse and thomas broyer's gwt-maven-plugin). @tbroyer p.s: when the module web page is accessed, it's still reaching out to codeserver on port 9876 (though codeserver has been configured to run on 9877)


Solution

  • First a small clarification: CodeServer is Super Dev Mode, just as DevMode is. The chief difference between CodeServer and DevMode is that DevMode also starts a simple application server on port 8888 by default.

    As such, you should not be running CodeServer and DevMode at the same time for the same project. If you are running two projects at the same time, naturally there will be a conflict of some kind, so picking different ports is required. With that said, CodeServer/DevMode is capable of running multiple modules at the same time, as long as their classpaths are compatible.

    Finally, running DevMode to run the built-in Jetty is deprecated in GWT (and is discouraged in the net.ltgt.gwt.maven plugin as well, see https://github.com/tbroyer/gwt-maven-archetypes/?tab=readme-ov-file#start-the-development-mode - except for windows, unless you apply the linked issue's workaround) - instead, run your own dev server, with CodeServer's launcherDir (or DevMode's warDir) set to create JS content that your own dev server can offer to the browser when it changes (the same as if you were editing js/html/css by hand, or using npm/etc).


    If the above doesn't solve your question, you might be hitting an issue where the browser stays connected to port 9876 even though the server has stopped, so you cannot restart the server. I've filed https://github.com/gwtproject/gwt/issues/9944 and will put up a patch soon to fix this.

    Here's the full stack trace, which shows that CodeServer is called as part of DevMode doing its own work (and showing the exception you are seeing):

         [java] java.io.IOException: Failed to bind to /127.0.0.1:9876
         [java]     at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:349)
         [java]     at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:310)
         [java]     at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
         [java]     at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:234)
         [java]     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
         [java]     at org.eclipse.jetty.server.Server.doStart(Server.java:401)
         [java]     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
         [java]     at com.google.gwt.dev.codeserver.WebServer.start(WebServer.java:138)
         [java]     at com.google.gwt.dev.codeserver.CodeServer.start(CodeServer.java:162)
         [java]     at com.google.gwt.dev.codeserver.CodeServer.main(CodeServer.java:104)
         [java]     at com.google.gwt.dev.codeserver.CodeServer.main(CodeServer.java:55)
         [java]     at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
         [java]     at java.base/java.lang.reflect.Method.invoke(Method.java:580)
         [java]     at com.google.gwt.dev.shell.SuperDevListener.runCodeServer(SuperDevListener.java:112)
         [java]     at com.google.gwt.dev.shell.SuperDevListener.start(SuperDevListener.java:91)
         [java]     at com.google.gwt.dev.DevMode.ensureCodeServerListener(DevMode.java:666)
         [java]     at com.google.gwt.dev.DevModeBase.doStartup(DevModeBase.java:785)
         [java]     at com.google.gwt.dev.DevMode.doStartup(DevMode.java:551)
         [java]     at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:888)
         [java]     at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:705)
         [java]     at com.google.gwt.dev.DevMode.main(DevMode.java:432)
         [java] Caused by: java.net.BindException: Address already in use
         [java]     at java.base/sun.nio.ch.Net.bind0(Native Method)
         [java]     at java.base/sun.nio.ch.Net.bind(Net.java:565)
         [java]     at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:344)
         [java]     at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:301)
         [java]     at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:89)
         [java]     at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
         [java]     ... 20 more