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

Netty BindException: Address already in use #82

Closed
grote opened this issue Mar 27, 2023 · 4 comments
Closed

Netty BindException: Address already in use #82

grote opened this issue Mar 27, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@grote
Copy link
Collaborator

grote commented Mar 27, 2023

Android 9 (SDK 28)

Exception java.net.BindException: Address already in use
  at sun.nio.ch.Net.bind0 (Net.java)
  at sun.nio.ch.Net.bind (Net.java:442)
  at sun.nio.ch.Net.bind (Net.java:434)
  at sun.nio.ch.ServerSocketChannelImpl.bind (ServerSocketChannelImpl.java:223)
  at sun.nio.ch.ServerSocketAdaptor.bind (ServerSocketAdaptor.java:74)
  at io.netty.channel.socket.nio.NioServerSocketChannel.doBind (NioServerSocketChannel.java:143)
  at io.netty.channel.AbstractChannel$AbstractUnsafe.bind (AbstractChannel.java:562)
  at io.netty.channel.DefaultChannelPipeline$HeadContext.bind (DefaultChannelPipeline.java:1334)
  at io.netty.channel.AbstractChannelHandlerContext.invokeBind (AbstractChannelHandlerContext.java:600)
  at io.netty.channel.AbstractChannelHandlerContext.bind (AbstractChannelHandlerContext.java:579)
  at io.netty.channel.DefaultChannelPipeline.bind (DefaultChannelPipeline.java:973)
  at io.netty.channel.AbstractChannel.bind (AbstractChannel.java:260)
  at io.netty.bootstrap.AbstractBootstrap$2.run (AbstractBootstrap.java:356)
  at io.netty.util.concurrent.AbstractEventExecutor.runTask (AbstractEventExecutor.java:174)
  at io.netty.util.concurrent.AbstractEventExecutor.safeExecute (AbstractEventExecutor.java:167)
  at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks (SingleThreadEventExecutor.java:470)
  at io.netty.channel.nio.NioEventLoop.run (NioEventLoop.java:569)
  at io.netty.util.concurrent.SingleThreadEventExecutor$4.run (SingleThreadEventExecutor.java:997)
  at io.netty.util.internal.ThreadExecutorMap$2.run (ThreadExecutorMap.java:74)
  at io.ktor.server.netty.EventLoopGroupProxy$Companion.create$lambda$1$lambda$0 (EventLoopGroupProxy.java:291)
  at io.ktor.server.netty.EventLoopGroupProxy$Companion$$InternalSyntheticLambda$1$49bdcb01cafe2b13b6659ff1549daa52ea0259f9d686f49c56cc383d4bfbd937$0.run (EventLoopGroupProxy.java:5)
  at io.netty.util.concurrent.FastThreadLocalRunnable.run (FastThreadLocalRunnable.java:30)
  at java.lang.Thread.run (Thread.java:764)
@grote grote added the bug Something isn't working label Mar 27, 2023
@grote
Copy link
Collaborator Author

grote commented Mar 27, 2023

Log from !81

14:00:09.154  I  Stopping sharing...
14:00:09.154  I  Stopping...
14:00:09.167  I  New state from: f-Zipped t-Stopping w-Started stop!
14:00:09.169  D  New state: Stopping
14:00:09.173  D  onDestroy
14:00:09.180  I  Stopping... (isFinishingDownloading: false)
14:00:09.196  I  Releasing lock
14:00:09.260  I  System.exit called, status: 0
14:00:09.260  I  VM exiting with result code 0, cleanup skipped.
14:00:09.286  D  TorService: Stopped
14:00:09.288  I  Stopped
14:00:09.290  I  New state from: f-Zipped t-Stopped w-Started stop!
---------------------------- PROCESS ENDED (12487) for package org.onionshare.android.nightly ----------------------------
14:00:09.290  E  Unhandled state: 
14:00:11.236  I  Application stopping: io.ktor.server.application.Application@169d5c69
14:00:11.238  I  Application stopped: io.ktor.server.application.Application@169d5c69
14:00:11.238  I  Stopped
14:00:11.243  I  New state from: f-Zipped t-Stopped w-Stopped stop!
14:00:11.243  E  Unhandled state: 
14:00:11.247  I  New state from: f-Added t-Stopped w-Stopped stop!
14:00:11.247  D  New state: FilesAdded
14:00:35.053  W  No such thread id for suspend: 20
14:00:35.055  W  No such thread id for suspend: 20
14:00:39.863  I  New state from: f-Added t-Stopped w-Stopped 
14:00:39.866  I  Starting...
14:00:39.873  I  New state from: f-Added t-Starting w-Stopped 
14:00:39.873  E  Unhandled state: 
14:00:39.878  I  New state from: f-Zipping t-Starting w-Stopped 
14:00:39.879  D  New state: Starting
---------------------------- PROCESS STARTED (12930) for package org.onionshare.android.nightly ----------------------------
14:00:40.157  W  libtor.so: unused DT entry: type 0x6ffffef5 arg 0x6b088
14:00:40.157  W  libtor.so: unused DT entry: type 0x6ffffffe arg 0x98504
14:00:40.157  W  libtor.so: unused DT entry: type 0x6fffffff arg 0x3
14:00:40.162  E  "libtor.so": ignoring 2-entry DT_PREINIT_ARRAY in shared library!
14:00:40.191  I  Acquired lock
14:00:40.270  D  TorService: Starting...
14:00:40.351  I  New state from: f-Zipping t-Starting w-Stopped 
14:00:40.351  D  New state: Starting
14:00:40.590  D  onStartCommand Intent { cmp=org.onionshare.android.nightly/org.onionshare.android.tor.ShareService }
14:00:40.622  D  TorService: Starting...
14:00:40.651  I  New state from: f-Zipping t-Starting w-Stopped 
14:00:40.651  D  New state: Starting
14:00:40.654  I  New state from: f-Zipped t-Starting w-Stopped 
14:00:40.656  I  Autoreload is disabled because the development mode is off.
14:00:40.663  I  Application started in 0.008 seconds.
14:00:40.663  I  Application started: io.ktor.server.application.Application@26fed4d0
14:00:44.881  E  FATAL EXCEPTION: DefaultDispatcher-worker-7
                 Process: org.onionshare.android.nightly, PID: 11705
                 java.net.BindException: bind failed: EADDRINUSE (Address already in use)
                 	at libcore.io.IoBridge.bind(IoBridge.java:99)
                 	at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:132)
                 	at java.net.ServerSocket.bind(ServerSocket.java:335)
                 	at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:143)
                 	at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:562)
                 	at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1334)
                 	at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:600)
                 	at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:579)
                 	at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:973)
                 	at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:260)
                 	at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:356)
                 	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
                 	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
                 	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
                 	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
                 	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
                 	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
                 	at io.ktor.server.netty.EventLoopGroupProxy$Companion.create$lambda$1$lambda$0(NettyApplicationEngine.kt:291)
                 	at io.ktor.server.netty.EventLoopGroupProxy$Companion.$r8$lambda$XgnKz7L6tCWRUaIAa7SVURwtFE4(NettyApplicationEngine.kt)
                 	at io.ktor.server.netty.EventLoopGroupProxy$Companion$$ExternalSyntheticLambda1.run(D8$$SyntheticClass)
                 	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
                 	at java.lang.Thread.run(Thread.java:818)
                 	Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@29d936c4, Dispatchers.Default]
                 Caused by: android.system.ErrnoException: bind failed: EADDRINUSE (Address already in use)
                 	at libcore.io.Posix.bind(Native Method)
                 	at libcore.io.ForwardingOs.bind(ForwardingOs.java:56)
                 	at libcore.io.IoBridge.bind(IoBridge.java:97)
                 	... 21 more

@grote
Copy link
Collaborator Author

grote commented Mar 28, 2023

A possible fix could be to let the webserver pick a random free port each time it starts and then let Tor know which port that is. Might need some tweaks to the state management, making sure the webserver gets started first or at least waiting for it to start won't introduce a deadlock with Tor needing this port.

@akwizgran
Copy link
Collaborator

That sounds good - it could help to simplify the state mangement, too, especially if we did the same when stopping.

@grote grote self-assigned this Aug 2, 2023
@grote
Copy link
Collaborator Author

grote commented Aug 2, 2023

Fixed by #92

@grote grote closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants