Skip to content

Commit 2053307

Browse files
authored
Merge pull request #802 from ahoppen/ahoppen/fix-sourcekit-lsp-hang
2 parents 731d5c6 + a6c67c1 commit 2053307

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/io.c

+17
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,23 @@ _dispatch_operation_perform(dispatch_operation_t op)
25102510
}
25112511
bSuccess = TRUE;
25122512
} else if (GetFileType(hFile) == FILE_TYPE_PIPE) {
2513+
// WriteFile with more bytes than are available in the
2514+
// buffer of a NOWAIT pipe will immediately return 0,
2515+
// so clamp our requested write length to make progress.
2516+
IO_STATUS_BLOCK iosb;
2517+
FILE_PIPE_LOCAL_INFORMATION fpli;
2518+
NTSTATUS status = _dispatch_NtQueryInformationFile(hFile,
2519+
&iosb, &fpli, sizeof(fpli), FilePipeLocalInformation);
2520+
if (NT_SUCCESS(status)) {
2521+
// WriteQuotaAvailable is unreliable in the presence
2522+
// of a blocking reader, when it can return zero, so only
2523+
// account for it otherwise
2524+
if (fpli.WriteQuotaAvailable > 0) {
2525+
len = MIN(len, fpli.WriteQuotaAvailable);
2526+
}
2527+
len = MIN(len, fpli.OutboundQuota);
2528+
}
2529+
25132530
OVERLAPPED ovlOverlapped = {};
25142531
bSuccess = WriteFile(hFile, buf, (DWORD)len,
25152532
(LPDWORD)&processed, &ovlOverlapped);

0 commit comments

Comments
 (0)