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

_nativeGetRemotePeer() throws or returns an exception whenever remoteAddress Socket's property getter is called! #48456

Closed
ahmadSaeedGoda opened this issue Feb 22, 2022 · 9 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.

Comments

@ahmadSaeedGoda
Copy link

ahmadSaeedGoda commented Feb 22, 2022

  • Dart SDK Version (dart --version): Dart SDK version: 2.16.1 (stable) (Tue Feb 8 12:02:33 2022 +0100) on "linux_x64"
  • Operating System is Linux UBUNTU.

_nativeGetRemotePeer() throws or returns an exception whenever remoteAddress Socket's property getter is called!

This _nativeGetRemotePeer() function appears to be a C native function called by Dart code. I have no access to debug the native code since debugger just reads or steps over the Dart code. So I would love to figure out how to debug the C native code or simply overcome such an issue!

I have no idea where this function's implementation resides. However, it's called or referenced in sync_socket_patch.dart file that lives in /home/$USER/snap/flutter/common/flutter/bin/cache/dart-sdk/lib/_internal/vm/bin/sync_socket_patch.dart.

Would you kindly advise?

@lrhn lrhn added analyzer-analysis-options area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. and removed analyzer-analysis-options labels Feb 23, 2022
@a-siva
Copy link
Contributor

a-siva commented Feb 24, 2022

@ahmadSaeedGoda the code for _nativeGetRemotePeer lives in sdk/bin/sync_socket.cc under SynchronousSocket_GetRemotePeer
If you want to debug the C native code yourself you would have to build a version of the Dart VM using instructions here https://github.com/dart-lang/sdk/wiki/Building and then run the build under a debugger, set a breakpoint at SynchronousSocket_GetRemotePeer and step through that code.

What kind of error do you get back when remoteAddress is called? Could it be that the socket is not connected and there is no remote when you are making this call ?

@a-siva a-siva added the needs-info We need additional information from the issue author (auto-closed after 14 days if no response) label Feb 24, 2022
@ahmadSaeedGoda
Copy link
Author

ahmadSaeedGoda commented Feb 26, 2022

"What kind of error do you get back when remoteAddress is called?" :
<type 'OSError' is not a subtype of type 'List<dynamic>' of 'function result' #0 _NativeSynchronousSocket._nativeGetRemotePeer (dart:io-patch/sync_socket_patch.dart) #1 _NativeSynchronousSocket.remoteAddress (dart:io-patch/sync_socket_patch.dart:136:18) #2 _RawSynchronousSocket.remoteAddress (dart:io-patch/sync_socket_patch.dart:28:48) #3 _RawSynchronousSocket.Eval () #4 _RawSynchronousSocket.Eval () #5 new SyncHttpClientResponse.processLine (package:sync_http/src/sync_http.dart:403:9) #6 _LineDecoder._process (package:sync_http/src/line_decoder.dart:45:16) #7 _LineDecoder.close (package:sync_http/src/line_decoder.dart:49:19) #8 new SyncHttpClientResponse (package:sync_http/src/sync_http.dart:422:21) #9 SyncHttpClientRequest.close (package:sync_http/src/sync_http.dart:104:12) #10 main (package:sync_http/main.dart:41:26) #11 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32) #12 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)>

"Could it be that the socket is not connected and there is no remote when you are making this call?" :

  • TBH I'm not sure whether I can answer this, However, the values of isClosed & isClosedRead & isClosedWrite properties of the _socket object as instance of _NativeSynchronousSocket are both equal to false. And the _socket object itself is a property of socket object which is an instance of _RawSynchronousSocket.
    Also I believe there is a remote when the call is made! because the remote property has value of an IP address until the call happens, then 'and only then' the error arises.. but there's no exception thrown that stops the execution! it's just the value of this remoteAddress property as well as remotePort changes to be the OSError mentioned above.. instead of String ip address as remoteAddress and int as remotePort.

Thanks anyway for the instructions to debug myself. I am going to try and keep you updated in case of any progress. In the mean time, waiting for your response and hope you can find the above mentioned info useful.

@no-response no-response bot removed the needs-info We need additional information from the issue author (auto-closed after 14 days if no response) label Feb 26, 2022
@ahmadSaeedGoda
Copy link
Author

couldn't find the code for _nativeGetRemotePeer under that path sdk/bin/sync_socket.cc though!

@a-siva
Copy link
Contributor

a-siva commented Feb 27, 2022

see sdk/sdk/lib/_internal/vm/bin)/sync_socket_patch.dart

It will have this code which links the Dart method to the corresponding native implementation

@pragma("vm:external-name", "SynchronousSocket_GetRemotePeer")
external List _nativeGetRemotePeer();

You should look for the method SynchronousSocket_GetRemotePeer in sdk/bin/sync_socket.cc

@ahmadSaeedGoda
Copy link
Author

ahmadSaeedGoda commented Feb 27, 2022

@a-siva I understand this:

see sdk/sdk/lib/_internal/vm/bin)/sync_socket_patch.dart

It will have this code which links the Dart method to the corresponding native implementation

@pragma("vm:external-name", "SynchronousSocket_GetRemotePeer")
external List _nativeGetRemotePeer();

But I don't have this: sdk/bin/sync_socket.cc!
It's not found on my system!

@ahmadSaeedGoda
Copy link
Author

Simply there is no C files at all inside the SDK folders. @a-siva

copybara-service bot pushed a commit that referenced this issue Mar 1, 2022
(These native implementations do not throw an exception, instead they
return on OSError object).

Related to the error seen in #48456

Change-Id: I6c98687d069073c4aa9d0344e79e777024590541
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234662
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
@a-siva
Copy link
Contributor

a-siva commented Mar 1, 2022

This CL https://dart-review.googlesource.com/c/sdk/+/234662 should fix the type error mismatch that is currently showing up.
It looks like an error is happening and the native method is throwing an exception. It should be possible to figure out the actual error with the above change.

Do you have a mechanism for building the VM and trying your test ?
If not if you could provide a reproduction we could investigate it here.

@ahmadSaeedGoda
Copy link
Author

ahmadSaeedGoda commented Mar 1, 2022

@a-siva Thank you for the follow up, this sounds amazing. Well, I am so happy with the progress so far, however I can't figure out how to use this change you've just pushed unfortunately. Kindly let me know how can I have a mechanism for building the VM and trying my own test :)

For the reproduction steps it's as easy as I am just using a Dart library for synchronous HTTP requests called sync_http and whenever I send any outbound request the response is always 400 Bad Request. While investigating and debugging it was clear that this exception occurs in every operation but doesn't throw to stop the execution of the program, Hence, I contacted you by reporting here.

Here's my client code/main.dart that uses the mentioned lib:

import 'sync_http.dart';

void main() {
  var uri = Uri.parse('someURL');
  var request = SyncHttpClient.getUrl(uri);
  var response = request.close();
  print('Response Status Code: ${response.statusCode}');
  print('Response Body: ${response.body}');
}

The pubspec.yaml of the lib is:

name: sync_http
version: 0.3.1-dev
description: Synchronous HTTP client for Dart.
homepage: https://github.com/google/sync_http.dart

environment:
  sdk: '>=2.12.0 <3.0.0'

dev_dependencies:
  pedantic: ^1.10.0-nullsafety.0
  test: ^1.16.0-nullsafety.8

If I can provide any further info or there is a reproduce steps template that I can fill out, I would be more than happy to do so.

@a-siva
Copy link
Contributor

a-siva commented Nov 10, 2023

Closing this issue as a CL to fix the type error mismatch has been submitted and the above reproduction steps works just fine with the latest version of Dart.

@a-siva a-siva closed this as completed Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.
Projects
None yet
Development

No branches or pull requests

3 participants