Skip to content

Commit 7c0a7d0

Browse files
committed
fix: notifications hang the server
1 parent 5dea8f6 commit 7c0a7d0

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/decoder.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
using namespace RpcUtils::detail;
99

10-
11-
1210
#define MIN_RPC_BYTES 4
1311

1412
#define MAX_BUFFER_SIZE 1024
@@ -50,7 +48,7 @@ class RpcDecoder {
5048
template<typename RType>
5149
bool get_response(const int msg_id, RType& result, RpcError& error) {
5250

53-
if (!packet_incoming() || packet_type()!=RESP_MSG) return false;
51+
if (!packet_incoming() || _packet_type!=RESP_MSG) return false;
5452

5553
MsgPack::Unpacker unpacker;
5654
unpacker.clear();
@@ -86,7 +84,7 @@ class RpcDecoder {
8684

8785
size_t get_request(uint8_t* buffer, size_t buffer_size) {
8886

89-
if (packet_type() != CALL_MSG && packet_type() != NOTIFY_MSG) {
87+
if (_packet_type != CALL_MSG && _packet_type != NOTIFY_MSG) {
9088
return 0; // No RPC
9189
}
9290

@@ -136,6 +134,7 @@ class RpcDecoder {
136134

137135
_packet_type = type;
138136
_packet_size = bytes_checked;
137+
break;
139138
} else {
140139
continue;
141140
}

src/server.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,30 @@ class RPCServer {
8787
if (msg_type == CALL_MSG) res_packer.serialize(resp_size, RESP_MSG, msg_id);
8888

8989
dispatcher.call(method, unpacker, res_packer);
90-
reset_rpc();
9190

9291
}
9392

9493
bool send_response() {
95-
if (res_packer.size() > 0) {
96-
return decoder->send_response(res_packer);
94+
if (_rpc_type == NO_MSG || res_packer.size() == 0) {
95+
return true; // No response to send
96+
}
97+
98+
if (_rpc_type == NOTIFY_MSG) {
99+
reset_rpc();
100+
return true;
97101
}
102+
103+
reset_rpc();
104+
return decoder->send_response(res_packer);
105+
98106
}
99107

100108
private:
101109
RpcDecoder<>* decoder = nullptr;
102110
RpcFunctionDispatcher<MAX_CALLBACKS> dispatcher;
103111
uint8_t _rpc_buffer[RPC_BUFFER_SIZE];
104112
size_t _rpc_size = 0;
105-
uint8_t _rpc_type = NO_MSG;
113+
int _rpc_type = NO_MSG;
106114
MsgPack::Packer res_packer;
107115

108116
void reset_rpc() {

0 commit comments

Comments
 (0)