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.
This commit is contained in:
Strahinja Val Markovic 2014-05-16 19:23:14 -07:00
parent 48031ab89a
commit d7195f6f19

View File

@ -61,6 +61,10 @@ signal.signal( signal.SIGINT, signal.SIG_IGN )
HMAC_SECRET_LENGTH = 16 HMAC_SECRET_LENGTH = 16
NUM_YCMD_STDERR_LINES_ON_CRASH = 30 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 = ( SERVER_CRASH_MESSAGE_STDERR_FILE = (
'The ycmd server SHUT DOWN (restart with :YcmRestartServer). ' + 'The ycmd server SHUT DOWN (restart with :YcmRestartServer). ' +
'Stderr (last {0} lines):\n\n'.format( NUM_YCMD_STDERR_LINES_ON_CRASH ) ) 'Stderr (last {0} lines):\n\n'.format( NUM_YCMD_STDERR_LINES_ON_CRASH ) )
@ -135,11 +139,14 @@ class YouCompleteMe( object ):
return return
self._user_notified_about_crash = True self._user_notified_about_crash = True
if self._server_stderr: if self._server_stderr:
with open( self._server_stderr, 'r' ) as server_stderr_file: try:
error_output = ''.join( server_stderr_file.readlines()[ with open( self._server_stderr, 'r' ) as server_stderr_file:
: - NUM_YCMD_STDERR_LINES_ON_CRASH ] ) error_output = ''.join( server_stderr_file.readlines()[
vimsupport.PostMultiLineNotice( SERVER_CRASH_MESSAGE_STDERR_FILE + : - NUM_YCMD_STDERR_LINES_ON_CRASH ] )
error_output ) vimsupport.PostMultiLineNotice( SERVER_CRASH_MESSAGE_STDERR_FILE +
error_output )
except IOError:
vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_STDERR_FILE_DELETED )
else: else:
vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_SAME_STDERR ) vimsupport.PostVimMessage( SERVER_CRASH_MESSAGE_SAME_STDERR )