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

Cannot convert argument of type class java.net.SocketException #39

Closed
preduseldavid opened this issue Apr 6, 2020 · 7 comments
Closed
Labels
bug Something isn't working released

Comments

@preduseldavid
Copy link

Description

Sometimes I get this error: Cannot convert argument of type class java.net.SocketException. I cannot reproduce it because sometimes appears, sometimes not... most of the time it doesn't appear
1586090928077

@preduseldavid preduseldavid added the bug Something isn't working label Apr 6, 2020
@Rapsssito
Copy link
Owner

@preduseldavid 👋👋👋. Could you provide more info about your environment? (RN version, library version, OS, etc.)

Could you also provide the socket configuration with some code for context?

@Rapsssito Rapsssito changed the title Runtime Error Cannot convert argument of type class java.net.SocketException Apr 6, 2020
@preduseldavid
Copy link
Author

The current version (just upgraded RN from 0.61.5 a few days ago - the bug was saw on RN 0.61.5)
System:
OS: Linux 5.3 Linux Mint 19.3 (Tricia)
CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
Memory: 2.90 GB / 15.60 GB
Shell: 4.4.20 - /bin/bash
Binaries:
Node: 13.12.0 - /usr/bin/node
Yarn: Not Found
npm: 6.14.4 - /usr/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Languages:
Python: 2.7.17 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.0 => 0.62.0
npmGlobalPackages:
react-native: Not Found

"react-native-tcp-socket": "^3.4.0" - I haven't tested it yet on this newer version (3.4.1)

@Rapsssito
Copy link
Owner

Thanks for the info, I will check it out!
It will really speed things up if you could provide the piece of code that throws this error (and maybe the socket initialization configuration object).

@preduseldavid
Copy link
Author

preduseldavid commented Apr 6, 2020

async _connectToServer() {
    var options = {host: this.serverHost, port: this.serverPort};

    NetInfo.fetch().then(state => {
      if (state.isConnected) {
        let client = TcpSocket.createConnection(options, () => {
          if (!this._toastInternetShow && this._reconnecting)
            Toast.show('Connected', false, 3000);
          else Toast.hide();

          this._reconnecting = 0;
          this._toastInternetShow = true;
          this._internetServiceEnabled = true;

          /* Do we have the location available? */
          let location = locationService.getLocation();
          if (locationService.locationIsAvailable(location)) {
            /* Register - send our location coords */
            this.updateLocation(location);
          }
          this.queueSendingPacketResume();
        });

        client.on('data', data => {
          InteractionManager.runAfterInteractions(() => {
            this._readEvent(data);
          });
        });

        client.on('error', error => {
          this.client.destroy();

          if (!this._reconnecting) {
            this._reconnecting = 1;
            Toast.show('Reconnecting');
            setTimeout(this._connectCallback, 1000);
          }
        });

        client.on('close', () => {
          this.client.destroy();

          if (!this._reconnecting) {
            this._reconnecting = 1;
            Toast.show('Reconnecting');
            setTimeout(this._connectCallback, 1000);
          }
        });

        this.client = client;
      } else {
        this._reconnecting = 1;
        this._internetServiceEnabled = false;
        if (this._toastInternetShow) {
          this._toastInternetShow = false;
          Toast.show('You are Offline', false, 3000);
        }

        setTimeout(this._connectCallback, 2000);
      }
    });
  }

and this is how I send a message:

    try {
      this.client.write(buf);
    } catch (e) {
      this.queueSendingPacket(buf);
    }

@Rapsssito
Copy link
Owner

@preduseldavid, thanks. I found the issue! It is related to the callback exception handling when writing on the socket. I will release a fix ASAP.

github-actions bot pushed a commit that referenced this issue Apr 6, 2020
## [3.4.2](v3.4.1...v3.4.2) (2020-04-06)

### Bug Fixes

* Fix write() callback invoking IOException objects ([f07ee07](f07ee07)), closes [#39](#39)
@github-actions
Copy link

github-actions bot commented Apr 6, 2020

🎉 This issue has been resolved in version 3.4.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Rapsssito
Copy link
Owner

@preduseldavid, I have released a fix that may resolve your issue 🎉. If the problem still persists, feel free to reopen this issue.

Looking at the root cause of the problem, the error Cannot convert argument of type class java.net.SocketException might be hiding another issue. If that is the case, please open a bug report and I will be happy to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

2 participants