Browse Source

Fix crash: posting Vim message from thread

Vim is not thread-safe so posting a message to Vim from a non-GUI thread causes
a crash *sometimes*. I was aware of this problem before, but didn't catch this
instance of it in code review.

Fixes #479.
Strahinja Val Markovic 11 years ago
parent
commit
4374da616e
2 changed files with 7 additions and 4 deletions
  1. 3 4
      python/ycm/completers/cs/cs_completer.py
  2. 4 0
      python/ycm/vimsupport.py

+ 3 - 4
python/ycm/completers/cs/cs_completer.py

@@ -167,10 +167,9 @@ class CsharpCompleter( ThreadedCompleter ):
     try:
     try:
       response = urllib2.urlopen( target, parameters )
       response = urllib2.urlopen( target, parameters )
       return json.loads( response.read() )
       return json.loads( response.read() )
-    except Exception as e:
-      if not silent:
-        vimsupport.PostVimMessage(
-          'OmniSharp : Could not connect to ' + target + ': ' + str( e ) )
+    except Exception:
+      # TODO: Add logging for this case. We can't post a Vim message because Vim
+      # crashes when that's done from a no-GUI thread.
       return None
       return None
 
 
 
 

+ 4 - 0
python/ycm/vimsupport.py

@@ -79,6 +79,10 @@ def NumLinesInBuffer( buffer ):
 
 
 
 
 def PostVimMessage( message ):
 def PostVimMessage( message ):
+  # TODO: Check are we on the main thread or not, and if not, force a crash
+  # here. This should make it impossible to accidentally call this from a
+  # non-GUI thread which *sometimes* crashes Vim because Vim is not thread-safe.
+  # A consistent crash should force us to notice the error.
   vim.command( "echohl WarningMsg | echomsg '{0}' | echohl None"
   vim.command( "echohl WarningMsg | echomsg '{0}' | echohl None"
                .format( EscapeForVim( message ) ) )
                .format( EscapeForVim( message ) ) )