From d7195f6f194c238c25f9e59966d7bd23b111b1ac Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Fri, 16 May 2014 19:23:14 -0700 Subject: [PATCH] Fixing race condition on server crash Crash handling code tried to read stderr log file, but the file can be deleted by the server befor we get to look at it. In such a case, we post a different error message (without the log output). Point is we do our best to get the error output if the user doesn't have g:ycm_server_keep_logfiles set. If we can't get the logfile, oh well. We tell the user to set that flag if they care. Fixes #974. --- python/ycm/youcompleteme.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 5c274f1e..0e6ee066 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -61,6 +61,10 @@ signal.signal( signal.SIGINT, signal.SIG_IGN ) HMAC_SECRET_LENGTH = 16 NUM_YCMD_STDERR_LINES_ON_CRASH = 30 +SERVER_CRASH_MESSAGE_STDERR_FILE_DELETED = ( + 'The ycmd server SHUT DOWN (restart with :YcmRestartServer). ' + 'Logfile was deleted; set g:ycm_server_keep_logfiles to see errors ' + 'in the future.' ) SERVER_CRASH_MESSAGE_STDERR_FILE = ( 'The ycmd server SHUT DOWN (restart with :YcmRestartServer). ' + 'Stderr (last {0} lines):\n\n'.format( NUM_YCMD_STDERR_LINES_ON_CRASH ) ) @@ -135,11 +139,14 @@ class YouCompleteMe( object ): return self._user_notified_about_crash = True if self._server_stderr: - with open( self._server_stderr, 'r' ) as server_stderr_file: - error_output = ''.join( server_stderr_file.readlines()[ - : - NUM_YCMD_STDERR_LINES_ON_CRASH ] ) - vimsupport.PostMultiLineNotice( SERVER_CRASH_MESSAGE_STDERR_FILE + - error_output ) + try: + with open( self._server_stderr, 'r' ) as server_stderr_file: + error_output = ''.join( server_stderr_file.readlines()[ + : - NUM_YCMD_STDERR_LINES_ON_CRASH ] ) + vimsupport.PostMultiLineNotice( SERVER_CRASH_MESSAGE_STDERR_FILE + + error_output ) + except IOError: + vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_STDERR_FILE_DELETED ) else: vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_SAME_STDERR )