Skip to content

Commit 401d143

Browse files
committed
tests/CSharpLanguageServer.Tests/Tooling.fs: do not fail to read response content if it is above 64K
1 parent f51cd9d commit 401d143

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/CSharpLanguageServer.Tests/Tooling.fs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,21 @@ let processClientEvent (state: ClientState) (post: ClientEvent -> unit) msg : As
305305
| None ->
306306
logMessage "RpcMessageReceived" "readNextJsonRpcMessage: EOF received when reading header"
307307
()
308+
308309
| Some header ->
309-
let content: byte[] = Array.zeroCreate header.ContentLength
310-
let bytesRead = stdout.Read(content)
310+
let bytesRead: List<byte> = List<byte>()
311+
312+
while bytesRead.Count < header.ContentLength do
313+
let numBytesToReadInThisChunk = Math.Min(header.ContentLength - bytesRead.Count, 4096)
314+
let chunk: byte[] = Array.zeroCreate numBytesToReadInThisChunk
315+
let chunkBytesRead: int = stdout.Read(chunk)
316+
for i in 0 .. (chunkBytesRead-1) do
317+
bytesRead.Add(chunk[i])
311318

312-
if bytesRead <> header.ContentLength then
313-
failwith "readNextJsonRpcMessage: could not read full content"
319+
if bytesRead.Count <> header.ContentLength then
320+
failwith (sprintf "readNextJsonRpcMessage: could not read the full content of response (bytesRead=%d; header.ContentLength=%d)" bytesRead.Count header.ContentLength)
314321

315-
let msg = Encoding.UTF8.GetString(content) |> JObject.Parse
322+
let msg = bytesRead |> _.ToArray() |> Encoding.UTF8.GetString |> JObject.Parse
316323

317324
post (RpcMessageReceived(Ok(Some msg)))
318325
with ex ->

0 commit comments

Comments
 (0)