8000 Lost connection to device when ffi with process a command · Issue #60486 · dart-lang/sdk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Lost connection to device when ffi with process a command #60486

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

Open
orange-pig opened this issue Apr 7, 2025 · 6 comments
Open

Lost connection to device when ffi with process a command #60486

orange-pig opened this issue Apr 7, 2025 · 6 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. triaged Issue has been triaged by sub team vm-native

Comments

@orange-pig
Copy link
orange-pig commented Apr 7, 2025

Steps to reproduce

  1. Impl a rust func process a command
  2. build to dynamic library copy to flutter Debug folder
  3. use the rust c func in flutter by ffi
  4. Lost connection to device after begin debug 60 ~ 90 seconds

Debug console log:

Connecting to VM Service at ws://127.0.0.1:6807/VVyk-SlkSlE=/ws
Connected to the VM Service.

Lost connection to device.

Exited.

OS: Windows 10 22H2

Flutter version:

Flutter 3.29.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision c236373904 (3 weeks ago) • 2025-03-13 16:17:06 -0400
Engine • revision 18b71d647a
Tools • Dart 3.7.2 • DevTools 2.42.3

Rust version

rustc 1.84.1 (e71f9a9a9 2025-01-27)

Expected results

The debugger won't exit

Actual results

The debugger exits, but the flutter process is still running and the window works fine

Code sample

Code sample

main.dart:

import 'dart:ffi';

import 'package:flutter/material.dart';

typedef _RunNative = Void Function();
typedef _RunDart = void Function();

void main() {
  final dylib = DynamicLibrary.open(r"./rust_command_lib.dll");
  final run = dylib.lookupFunction<_RunNative, _RunDart>('run');
  run();

  runApp(const MyApp());
}

lib.rs:

use std::process::Command;

#[no_mangle]
pub extern "C" fn run() {
    let output = Command::new("calc").output().expect("failed running calc");
    let stdout = String::from_utf8_lossy(&output.stdout);
    println!("{}", stdout)
}

Cargo.toml:

[package]
name = "rust_command_lib"
version = "0.1.0"
edition = "2021"

[dependencies]

[lib]
name = "rust_command_lib"
crate-type = ["cdylib"]

Screenshots or Video

Screenshots / Video demonstration

Image

@mraleph
Copy link
Member
mraleph commented Apr 7, 2025

and the window works fine

Is the window actually still interactive? (e.g. does it do anything when you press +)?

@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. vm-native labels Apr 7, 2025
@orange-pig
Copy link
Author

Is the window actually still interactive? (e.g. does it do anything when you press +)?

Yes, look like only debuger loss connect.

Additional:

  1. Run the release execute, and a cmd window will appear when it starts.
  2. There is a small chance that the main window will automatically exit

@a-siva a-siva added the triaged Issue has been triaged by sub team label Apr 9, 2025
@a-siva
Copy link
Contributor
a-siva commented Apr 9, 2025

//cc @derekxu16 @jyameo could one of you try reproducing the above scenario to see if the problem is reproducible,

@derekxu16
Copy link
Member

I wasn't able to reproduce it. I tried using the exact same code as in the repro instructions with Flutter 3.29.2 on Windows. I left the app running for 3 minutes and never saw "Lost connection to device."

@orange-pig
Copy link
Author

Something is wrong maybe.
A demo that must appear on my windows: https://github.com/orange-pig/demo_issue_lost_connection_to_device

@orange-pig
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, and the AOT and JIT backends. triaged Issue has been triaged by sub team vm-native
Projects
None yet
Development

No branches or pull requests

5 participants
0