@@ -66,11 +66,10 @@ public function __construct(pq\Connection $handle) {
66
66
67
67
$ this ->poll = Loop::onReadable ($ this ->handle ->socket , static function ($ watcher ) use (&$ deferred , &$ listeners , &$ handle ) {
68
68
if ($ handle ->poll () === pq \Connection::POLLING_FAILED ) {
69
+ $ exception = new ConnectionException ($ handle ->errorMessage );
69
70
$ handle = null ; // Marks connection as dead.
70
71
Loop::disable ($ watcher );
71
72
72
- $ exception = new ConnectionException ($ handle ->errorMessage );
73
-
74
73
foreach ($ listeners as $ listener ) {
75
74
$ listener ->fail ($ exception );
76
75
}
@@ -97,9 +96,22 @@ public function __construct(pq\Connection $handle) {
97
96
}
98
97
});
99
98
100
- $ this ->await = Loop::onWritable ($ this ->handle ->socket , static function ($ watcher ) use (&$ deferred , $ handle ) {
101
- if (!$ handle ->flush ()) {
102
- return ; // Not finished sending data, continue polling for writability.
99
+ $ this ->await = Loop::onWritable ($ this ->handle ->socket , static function ($ watcher ) use (&$ deferred , &$ listeners , &$ handle ) {
100
+ try {
101
+ if (!$ handle ->flush ()) {
102
+ return ; // Not finished sending data, continue polling for writability.
103
+ }
104
+ } catch (pq \Exception $ exception ) {
105
+ $ exception = new ConnectionException ("Flushing the connection failed " , 0 , $ exception );
106
+ $ handle = null ; // Marks connection as dead.
107
+
108
+ foreach ($ listeners as $ listener ) {
109
+ $ listener ->fail ($ exception );
110
+ }
111
+
112
+ if ($ deferred !== null ) {
113
+ $ deferred ->fail ($ exception );
114
+ }
103
115
}
104
116
105
117
Loop::disable ($ watcher );
0 commit comments