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

[Windows] [ServerSocket] ServerSocket.Close() not closing socket and continue working #54882

Closed
NickNevzorov opened this issue Feb 12, 2024 · 1 comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-as-intended Closed as the reported issue is expected behavior library-io

Comments

@NickNevzorov
Copy link

Steps to reproduce

  1. Run project
  2. Connect to socket
  3. Send data
  4. Wait while close() executed
  5. Send data again

Expected results

ServerSocket may close socket

Actual results

ServerSocket did not close socket

Code sample

Code sample
import 'dart:convert';
import 'dart:io';

void main() async {

  ServerSocket messagesSocket = await ServerSocket.bind(InternetAddress.anyIPv4, 11000);
  print('Messages listen: ' + Platform.localHostname + ':' + messagesSocket!.port.toString());

  messagesSocket?.listen((Socket client) {
    client.listen((data) async {
      var message = utf8.decode(data).trim();
      print("server listen  : $message");
    });
  });

  await Future.delayed(Duration(seconds: 10));

  await messagesSocket.close();
  print("server close");

}

Logs

Logs
flutter: Messages listen: Nick-PC:11000
flutter: server listen  : <EOF>
flutter: server close
flutter: server listen  : <EOF>
flutter: server listen  : <EOF>
flutter: server listen  : <EOF>

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.16.9, on Microsoft Windows [Version 10.0.19045.3930], locale ru-UA)
    • Flutter version 3.16.9 on channel stable at d:\sdk\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 41456452f2 (2 weeks ago), 2024-01-25 10:06:23 -0800
    • Engine revision f40e976bed
    • Dart version 3.2.6
    • DevTools version 2.28.5

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at d:\sdk\android\sdk\
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = d:\sdk\android\sdk\
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.7.34024.191
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2023.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = C:\Program Files\Android\Android Studio
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] VS Code (version 1.85.1)
    • VS Code at C:\Users\Николай\AppData\Local\Programs\Microsoft VS Code
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19045.3930]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 121.0.6167.141
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 121.0.2277.106

[√] Network resources
    • All expected network resources are available.

• No issues found!
PS C:\1\untitled1> flutter doctor   
Doctor summary (to see all details, run flutter doctor -v):
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.3)
[√] Android Studio (version 2023.1)
[√] VS Code (version 1.85.1)
[√] Connected device (3 available)
[√] Network resources

• No issues found!
PS C:\1\untitled1> ^C
PS C:\1\untitled1>
PS C:\1\untitled1> flutter doctor -v
[√] Flutter (Channel stable, 3.16.9, on Microsoft Windows [Version 10.0.19045.3930], locale ru-UA)
    • Flutter version 3.16.9 on channel stable at d:\sdk\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 41456452f2 (2 weeks ago), 2024-01-25 10:06:23 -0800
    • Engine revision f40e976bed
    • Dart version 3.2.6
    • DevTools version 2.28.5

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at d:\sdk\android\sdk\
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = d:\sdk\android\sdk\
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.7.34024.191
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2023.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = C:\Program Files\Android\Android Studio
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] VS Code (version 1.85.1)
    • VS Code at C:\Users\Николай\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19045.3930]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 121.0.6167.141
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 121.0.2277.106

[√] Network resources
    • All expected network resources are available.

• No issues found!
@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io labels Feb 12, 2024
@mraleph
Copy link
Member

mraleph commented Feb 12, 2024

I think this is working as intended for BSD sockets. Closing listening socket does not affect connections already established - it only prevents new connections from being formed. There is no implicit parent-child relationship between listening socket and sockets created for each incoming connection. They are all independent sockets.

I think in some languages IO implementation maintains a list of active connections on the server socket and shuts all connections down when server socket is closed by the user, but Dart implementation does not do that - so if you want this behavior you will need to implement it manually.

@mraleph mraleph closed this as completed Feb 12, 2024
@mraleph mraleph added the closed-as-intended Closed as the reported issue is expected behavior label Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-as-intended Closed as the reported issue is expected behavior library-io
Projects
None yet
Development

No branches or pull requests

3 participants