Skip to content

Commit

Permalink
Fix NLS stack overflow on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
yannham committed Dec 11, 2024
1 parent 800a949 commit d8e18b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ fn check_annotated_nickel_file(path: &str) {
let test: TestCase<Test> =
read_annotated_test_case(path).expect("Failed to parse annotated program");

// By default, cargo runs tests with a 2MB stack, which we can overflow in
// debug mode. To avoid this we run the tests with an increased stack size.
// By default, cargo runs tests with a 2MB stack, which is easy to overflow. To avoid this we
// run the tests with an increased stack size.
const STACK_SIZE: usize = 4 * 1024 * 1024;
let path = String::from(project_root().join(path).to_string_lossy());

Expand Down
15 changes: 14 additions & 1 deletion lsp/nls/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs, io, path::PathBuf};
use std::{fs, io, path::PathBuf, thread};

use anyhow::Result;

Expand Down Expand Up @@ -29,6 +29,10 @@ mod usage;
mod utils;
mod world;

// Default stack size is 1MB on Windows, which is too small. We make it 8MB, which is the default
// size on Linux.
const STACK_SIZE: usize = 8 * 1024 * 1024;

use crate::{config::LspConfig, trace::Trace};

#[derive(clap::Parser, Debug)]
Expand Down Expand Up @@ -59,6 +63,15 @@ struct Options {
}

fn main() -> Result<()> {
let handle = thread::Builder::new()
.stack_size(STACK_SIZE)
.spawn(run)
.unwrap();

handle.join().unwrap()
}

fn run() -> Result<()> {
use clap::Parser;

env_logger::init();
Expand Down
1 change: 1 addition & 0 deletions lsp/nls/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl Server {
.send(Message::Response(response))
.unwrap();
}

pub(crate) fn notify(&mut self, notification: Notification) {
trace!("Sending notification: {:#?}", notification);
self.connection
Expand Down

0 comments on commit d8e18b4

Please sign in to comment.