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

NetworkOnMainThread exception when attempting to send rawlines while connected to a IRC bouncer #218

Open
harkin opened this issue May 1, 2016 · 0 comments

Comments

@harkin
Copy link

harkin commented May 1, 2016

I'm connecting to a ZNC bouncer running on a server somewhere to access some irc networks.

When I try to do anything that ultimately hits this method (for example, /nick or /join) nothing happens.

Debugging a little, an exception is being thrown here. The exception stacktrace thrown is included at the bottom. TL;DR it's a NetworkOnMainThreadException.

When I connect to an irc network directly I do not see that exception and can change nick, join channels etc as you'd normally expect.

What's the difference between connecting to my bouncer and connecting to an IRC network directly? No clue. It might be latency and that going direct is fast enough that it doesn't trigger the exception (though I kinda doubt this as you'd still expect slower connections to see this issue then). From the debugging information I can see that I am on the main thread in both cases when attempting to write to the buffer.

Whatever the reason networking on the main thread is bad. When I wrap that buffer write in something like this everything works as expected when connecting to the bouncer:

    Executors.newSingleThreadExecutor().submit(new Runnable() {
        @Override public void run() {
            bwriter.write(line + "\r\n");
            bwriter.flush();   
        }
    });

I can submit a fix for this easily enough but I don't want to be naively spinning up threads here there and everywhere. I suspect everything could be put on a background thread a long ways up the line instead of just before writing to the buffer but don't have enough context right now to see where the best place might be. If you have a suggestion I can go about fixing it :) (I will submit a PR soon either way, this bug is really annoying me)

This is also an issue in the version of Yaaic published on the play store.

Exception stacktrace:

05-01 20:09:58.368 25995-25995/org.yaaic W/System.err: android.os.NetworkOnMainThreadException
05-01 20:09:58.368 25995-25995/org.yaaic W/System.err:     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)
05-01 20:09:58.368 25995-25995/org.yaaic W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:755)
05-01 20:09:58.368 25995-25995/org.yaaic W/System.err:     at java.io.OutputStreamWriter.flushBytes(OutputStreamWriter.java:170)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:161)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at java.io.BufferedWriter.flush(BufferedWriter.java:124)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at org.yaaic.protocol.OutputThread.sendRawLine(OutputThread.java:66)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at org.yaaic.protocol.InputThread.sendRawLine(InputThread.java:56)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at org.yaaic.protocol.IRCClient.sendRawLine(IRCClient.java:386)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at org.yaaic.protocol.IRCClient.changeNick(IRCClient.java:477)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at org.yaaic.command.handler.NickHandler.execute(NickHandler.java:46)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at org.yaaic.command.CommandParser.handleClientCommand(CommandParser.java:179)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at org.yaaic.command.CommandParser.parse(CommandParser.java:236)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at org.yaaic.fragment.ConversationFragment.sendMessage(ConversationFragment.java:777)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at org.yaaic.fragment.ConversationFragment.sendCurrentMessage(ConversationFragment.java:729)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at org.yaaic.fragment.ConversationFragment.access$100(ConversationFragment.java:92)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at org.yaaic.fragment.ConversationFragment$2.onClick(ConversationFragment.java:268)
05-01 20:09:58.369 25995-25995/org.yaaic W/System.err:     at android.view.View.performClick(View.java:5204)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants