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

Access to 'receive' and 'toSendPort()' needs to throw an exception when the used on a closed port #7548

Closed
a-siva opened this issue Dec 20, 2012 · 4 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue library-isolate

Comments

@a-siva
Copy link
Contributor

a-siva commented Dec 20, 2012

The following test does not result in any exceptions even though it
is accessing a closed port.

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// PackageRoot=packages/

library package_isolate_test;
import 'package:shared.dart' as shared;
import 'dart:isolate';
import '../../../pkg/unittest/lib/unittest.dart';

expectResponse() {
  port.receive(expectAsync2((msg, r) {
    expect('isolate', msg);
    expect('main', shared.output);
    port.close();
    print("In expectResponse reply $msg");
    print("Value of port in reply = ${port.hashCode}");
  }));
}

void main() {
  test("package in spawnFunction()", () {
    print("Set up expectResponse spawnFunction");
    try {
      print("Value of port1 = ${port.hashCode}");
      expectResponse();
      shared.output = 'main';
      var sendPort = spawnFunction(isolate_main);
      sendPort.send("sendPort", port.toSendPort());
     } catch (e, trace) {
      print(e);
      print(trace);
     }
  });
  
  test("package in spawnUri() of sibling file", () {
    print("Set up expectResponse spawnUri1");
    try {
      print("Value of port1 = ${port.hashCode}");
      expectResponse();
      shared.output = 'main';
      var sendPort = spawnUri('sibling_isolate.dart');
      print("Value of port2 = ${port.hashCode}");
      print("Value of send port = ${port.toSendPort()}");
      sendPort.send('sendPort', port.toSendPort());
     } catch (e, trace) {
      print(e);
      print(trace);
     }
  });

  test("package in spawnUri() of file in folder", () {
    print("Set up expectResponse spawnUri2");
    try {
      expectResponse();
      shared.output = 'main';
      var sendPort = spawnUri('test_folder/folder_isolate.dart');
      sendPort.send('sendPort', port.toSendPort());
     } catch (e, trace) {
      print(e);
      print(trace);
     }
  });

  print("Done setting up xpectResponse");
}

void isolate_main() {
  shared.output = 'isolate';
  port.receive((msg, replyTo) {
    replyTo.send(shared.output);
  });
}

@sethladd
Copy link
Contributor

Added Triaged label.

@iposva-google
Copy link
Contributor

As this is more of a library question, I am sending this over to Florian, but I agree that we should change this in the VM implementation now.


cc @a-siva.
Removed Area-VM label.
Added Area-Library label.

@lrhn
Copy link
Member

lrhn commented Apr 30, 2014

It's probably an error to try to listen after closing. Makes sense to throw a StateError.
It could break existing programs that are not careful about the order of operations (and which didn't have to be because we allowed it).


Added Library-Isolate label.

@lrhn
Copy link
Member

lrhn commented Oct 6, 2014

A ReceivePort is now a single-subscription Stream, and follows the Stream behavior.
For RawReceivePort, changing the handler isn't the same as listening, and there is no reason to disallow that after closing.
Same for getting the sendPort - it can still be used as a capability even after the receive port is closed.


Added NotPlanned label.

@a-siva a-siva added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-isolate closed-not-planned Closed as we don't intend to take action on the reported issue labels Oct 6, 2014
This issue was closed.
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-not-planned Closed as we don't intend to take action on the reported issue library-isolate
Projects
None yet
Development

No branches or pull requests

4 participants