Skip to content

Commit 23c9645

Browse files
committed
Read from the ws buffer immediately, it may be disposed afterwards
1 parent 4f56c51 commit 23c9645

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

libsignal-service-dotnet/push/ProvisioningSocket.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class ProvisioningSocket
1414
{
1515
private ISignalWebSocket SignalWebSocket;
1616
private readonly string WsUri;
17-
private readonly BlockingCollection<Stream> IncomingRequests = new BlockingCollection<Stream>(new ConcurrentQueue<Stream>());
17+
private readonly BlockingCollection<WebSocketMessage> IncomingRequests = new BlockingCollection<WebSocketMessage>(new ConcurrentQueue<WebSocketMessage>());
1818

1919
public ProvisioningSocket(string httpUri, ISignalWebSocketFactory webSocketFactory, CancellationToken token)
2020
{
@@ -26,10 +26,11 @@ public ProvisioningSocket(string httpUri, ISignalWebSocketFactory webSocketFacto
2626

2727
private void SignalWebSocket_MessageReceived(object sender, SignalWebSocketMessageReceivedEventArgs e)
2828
{
29-
IncomingRequests.Add(e.Message);
29+
var msg = WebSocketMessage.Parser.ParseFrom(e.Message);
30+
IncomingRequests.Add(msg);
3031
}
3132

32-
private async Task<Stream> TakeAsync(CancellationToken token)
33+
private async Task<WebSocketMessage> TakeAsync(CancellationToken token)
3334
{
3435
return await Task.Run(() =>
3536
{
@@ -40,14 +41,13 @@ private async Task<Stream> TakeAsync(CancellationToken token)
4041
public async Task<ProvisioningUuid> GetProvisioningUuid(CancellationToken token)
4142
{
4243
await SignalWebSocket.ConnectAsync();
43-
Stream raw = await TakeAsync(token);
44-
return ProvisioningUuid.Parser.ParseFrom(WebSocketMessage.Parser.ParseFrom(raw).Request.Body);
44+
var msg = await TakeAsync(token);
45+
return ProvisioningUuid.Parser.ParseFrom(msg.Request.Body);
4546
}
4647

4748
public async Task<ProvisionMessage> GetProvisioningMessage(CancellationToken token, IdentityKeyPair tmpIdentity)
4849
{
49-
Stream raw = await TakeAsync(token);
50-
WebSocketMessage msg = WebSocketMessage.Parser.ParseFrom(raw);
50+
var msg = await TakeAsync(token);
5151
return new ProvisioningCipher(null).Decrypt(tmpIdentity, msg.Request.Body.ToByteArray());
5252
}
5353
}

0 commit comments

Comments
 (0)