@@ -76,12 +76,6 @@ func (s *Server) Start() {
76
76
"connection_id" , s .callbackContext .ConnectionId .String (),
77
77
)
78
78
s .Protocol .Start ()
79
- // Start goroutine to cleanup resources on protocol shutdown
80
- go func () {
81
- <- s .Protocol .DoneChan ()
82
- close (s .requestTxIdsResultChan )
83
- close (s .requestTxsResultChan )
84
- }()
85
79
})
86
80
}
87
81
@@ -103,13 +97,14 @@ func (s *Server) RequestTxIds(
103
97
return nil , err
104
98
}
105
99
// Wait for result
106
- txIds , ok := <- s . requestTxIdsResultChan
107
- if ! ok {
100
+ select {
101
+ case <- s . DoneChan ():
108
102
return nil , protocol .ProtocolShuttingDownError
103
+ case txIds := <- s .requestTxIdsResultChan :
104
+ // Update ack count for next call
105
+ s .ackCount = len (txIds )
106
+ return txIds , nil
109
107
}
110
- // Update ack count for next call
111
- s .ackCount = len (txIds )
112
- return txIds , nil
113
108
}
114
109
115
110
// RequestTxs requests the content of the requested TX identifiers from the remote node's mempool
@@ -127,11 +122,12 @@ func (s *Server) RequestTxs(txIds []TxId) ([]TxBody, error) {
127
122
return nil , err
128
123
}
129
124
// Wait for result
130
- txs , ok := <- s . requestTxsResultChan
131
- if ! ok {
125
+ select {
126
+ case <- s . DoneChan ():
132
127
return nil , protocol .ProtocolShuttingDownError
128
+ case txs := <- s .requestTxsResultChan :
129
+ return txs , nil
133
130
}
134
- return txs , nil
135
131
}
136
132
137
133
func (s * Server ) messageHandler (msg protocol.Message ) error {
@@ -163,12 +159,6 @@ func (s *Server) handleReplyTxIds(msg protocol.Message) error {
163
159
"role" , "server" ,
164
160
"connection_id" , s .callbackContext .ConnectionId .String (),
165
161
)
166
- // Check for shutdown
167
- select {
168
- case <- s .Protocol .DoneChan ():
169
- return protocol .ProtocolShuttingDownError
170
- default :
171
- }
172
162
msgReplyTxIds := msg .(* MsgReplyTxIds )
173
163
s .requestTxIdsResultChan <- msgReplyTxIds .TxIds
174
164
return nil
@@ -182,12 +172,6 @@ func (s *Server) handleReplyTxs(msg protocol.Message) error {
182
172
"role" , "server" ,
183
173
"connection_id" , s .callbackContext .ConnectionId .String (),
184
174
)
185
- // Check for shutdown
186
- select {
187
- case <- s .Protocol .DoneChan ():
188
- return protocol .ProtocolShuttingDownError
189
- default :
190
- }
191
175
msgReplyTxs := msg .(* MsgReplyTxs )
192
176
s .requestTxsResultChan <- msgReplyTxs .Txs
193
177
return nil
0 commit comments