Executing std.process synchronously with vibe.d sometimes silently hangs on the server

I wrote a vibe.d web interface for clang-format , when this input is presented when using LLVM style, the server freezes.

Code for processing POST:

 void post(string style, string code) { import std.algorithm; import std.file; import std.conv; import std.process; auto pipes = pipeProcess(["clang-format", "-style="~style], Redirect.stdout | Redirect.stdin); scope(exit) wait(pipes.pid); pipes.stdin.write(code); pipes.stdin.close; pipes.pid.wait; code = pipes.stdout.byLine.joiner.to!string; string selectedStyle = style; render!("index.dt", styles, code, selectedStyle); } 

This probably should not be done in a blocking way, but I don't understand how to do this asynchronously. I tried to wrap the contents of the function in runTask , but I could not figure out how to call it correctly.

How can I make it reliable?

+6
source share
1 answer

You are probably writing too much data to the stdin program without reading its stdout . Since the channel buffer size is limited, this causes the executable to block writing to its stdout , which in turn causes your program to block writing to its stdin .

The solution is to read data while writing. An easy way to do this is to create a second stream that reads data while the main stream writes it.

+1
source

Source: https://habr.com/ru/post/989121/


All Articles