[objective_c] Receive port cleanup missing when block trampoline resolution fails
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- dart
- Domain
- mobile-dev
Research direction
Read pkgs/objective_c/lib/src/internal.dart, especially newBlockPort and newBlockingBlockPort. Trace what resources each helper creates before invoking maker, then find the relevant tests for trampoline resolution failures. Ensure those resources are released while the original ArgumentError is preserved, and confirm the receive port no longer keeps the process alive.
Written by the indexing model from the issue text.
Description
While investigating #2953, I noticed that newBlockPort and newBlockingBlockPort do not clean up allocated resources when native trampoline resolution fails.
Both helpers create a RawReceivePort before invoking maker. If native symbol resolution throws an ArgumentError, attachPortBlockFinalizer is never reached, leaving the receive port open. In the blocking variant, the NativeCallable may also remain unclosed.
Relevant source:
Minimal reproduction
import 'dart:ffi';
import 'dart:isolate';
@Native<Int32 Function()>(
symbol: 'intentionally_missing_symbol',
isLeaf: true,
)
external int missingFunction();
void createBlock(int Function() maker, bool cleanup) {
final port = RawReceivePort()
..keepIsolateAlive = true;
port.handler = (message) {};
try {
maker();
} catch (_) {
if (cleanup) {
port.close();
}
rethrow;
}
port.close();
}
void main(List<String> args) {
try {
createBlock(missingFunction, args.contains('--cleanup'));
} catch (e) {
print(e.runtimeType);
print(e);
}
print('End of main');
}
Steps to reproduce
timeout 5s dart repro.dart
echo "Exit code: $?"
timeout 5s dart repro.dart --cleanup
echo "Exit code: $?"
Observed behavior
Without cleanup:
ArgumentError
...
End of main
Exit code: 124
With cleanup:
ArgumentError
...
End of main
Exit code: 0
Without cleanup, the process hangs despite reaching the end of main. Explicitly closing the receive port allows the process to terminate normally.
Expected behavior
Resources allocated before invoking the native trampoline should be released if trampoline resolution fails, while preserving the original error.
Environment
- Dart SDK: 3.13.2 (stable)
- Platform: Linux x64 (WSL)
- Upstream commit:
2c63bb68a
The minimal reproduction demonstrates the failure pattern independently of package:objective_c. I haven't verified the full Objective-C integration scenario on macOS or independently reproduced the potential NativeCallable leak.
- Dominant language
- Dart
- Stars
- 280
- Forks
- 166
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 33
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dart-lang/native
-
Proposal: targetIOSVersion may need to be updated to 15 for Flutter 3.47+Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dart-lang/native#3594 · 1 comment ·
Maintainers usually reply within 2 days
-
package:ffigen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dart-lang/native#1564 · 2 comments ·
Maintainers usually reply within 2 days
-
[ffigen] Gemini's friction logPossibly taken @liamappelbe claimed this today. Openneeds-triage package:ffigen
dart-lang/native#3837 · 1 assignee ·
Maintainers usually reply within 2 days
-
[jnigen] Gemini's friction logPossibly taken @liamappelbe claimed this today. Openlang-java needs-triage package:jni package:jni_flutter package:jnigen
dart-lang/native#3836 · 1 assignee ·
Maintainers usually reply within 2 days
-
[jni] Reference leaks in JNIPossibly taken @liamappelbe claimed this 7 days ago. Openlang-java package:jni package:jni_flutter package:jnigen
dart-lang/native#3822 · 1 assignee ·
Maintainers usually reply within 2 days
All issues in dart-lang/native
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 75/100
nucleus-ffm/foss_warn#337 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
docs good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 75/100