Fix a race condition.

If the peer was closed and then the channel closed, we would
double-complete a completer.

R=jmesserly@google.com

Review URL: https://codereview.chromium.org//1890003002 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 649c738..feb1001 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 2.0.1
+
+* Fix a race condition in which a `StateError` could be top-leveled if
+  `Peer.close()` was called before the underlying channel closed.
+
 ## 2.0.0
 
 * **Breaking change:** all constructors now take a `StreamChannel` rather than a
diff --git a/lib/src/channel_manager.dart b/lib/src/channel_manager.dart
index 35d75a6..8f66870 100644
--- a/lib/src/channel_manager.dart
+++ b/lib/src/channel_manager.dart
@@ -56,7 +56,9 @@
           _doneCompleter.completeError(error, stackTrace);
           _channel.sink.close();
         },
-        onDone: _doneCompleter.complete,
+        onDone: () {
+          if (!_doneCompleter.isCompleted) _doneCompleter.complete();
+        },
         cancelOnError: true);
 
     return done;
diff --git a/pubspec.yaml b/pubspec.yaml
index 0d90546..8cb0dc8 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: json_rpc_2
-version: 2.0.1-dev
+version: 2.0.1
 author: Dart Team <misc@dartlang.org>
 description: An implementation of the JSON-RPC 2.0 spec.
 homepage: http://github.com/dart-lang/json_rpc_2