Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
Handle PoisonError when locking session
Browse files Browse the repository at this point in the history
The Racer.session mutex can become poisoned if a racer call panics since
this mutex is guaranteed to be held at that time. The Session type
shouldn't panic while modifying its internal state, and it should be
safe to recover from the PoisonError that occurs.
  • Loading branch information
jwilm committed Dec 22, 2015
1 parent cca3695 commit 414482a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/engine/racer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ impl<'a> SemanticEngine for Racer<'a> {

fn find_definition(&self, ctx: &Context) -> Result<Option<Definition>> {
let (query_src, pos, path) = self.build_racer_args(ctx);
let session = self.session.lock().unwrap();
let session = match self.session.lock() {
Ok(guard) => guard,
Err(poisoned) => poisoned.into_inner()
};

// TODO catch_panic: apparently this can panic! in a string operation. Something about pos
// not landing on a character boundary.
Expand Down Expand Up @@ -108,7 +111,10 @@ impl<'a> SemanticEngine for Racer<'a> {

fn list_completions(&self, ctx: &Context) -> Result<Option<Vec<Completion>>> {
let (query_src, pos, path) = self.build_racer_args(ctx);
let session = self.session.lock().unwrap();
let session = match self.session.lock() {
Ok(guard) => guard,
Err(poisoned) => poisoned.into_inner()
};

let matches = ::racer::core::complete_from_file(query_src, path, pos, *session);

Expand Down

0 comments on commit 414482a

Please sign in to comment.