Skip to content

Commit f533e90

Browse files
rabbit_disk_monitor: handle gen_server timeouts to reduce log noise
References #8836.
1 parent 7037c88 commit f533e90

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

deps/rabbit/src/rabbit_disk_monitor.erl

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ internal_update(State = #state{limit = Limit,
282282
os = OS,
283283
port = Port}) ->
284284
CurrentFree = get_disk_free(Dir, OS, Port),
285+
%% note: 'NaN' is considered to be less than a number
285286
NewAlarmed = CurrentFree < Limit,
286287
case {Alarmed, NewAlarmed} of
287288
{false, true} ->
@@ -321,19 +322,28 @@ get_disk_free(Dir, {win32, _}, not_used) ->
321322
end,
322323
% Note: we can use os_mon_sysinfo:get_disk_info/1 after the following is fixed:
323324
% https://github.com/erlang/otp/issues/6156
324-
[DriveInfoStr] = lists:filter(F, os_mon_sysinfo:get_disk_info()),
325-
326-
% Note: DriveInfoStr is in this format
327-
% "C:\\ DRIVE_FIXED 720441434112 1013310287872 720441434112\n"
328-
[DriveLetter, $:, $\\, $\s | DriveInfo] = DriveInfoStr,
329-
330-
% https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskfreespaceexa
331-
% lib/os_mon/c_src/win32sysinfo.c:
332-
% if (fpGetDiskFreeSpaceEx(drive,&availbytes,&totbytes,&totbytesfree)){
333-
% sprintf(answer,"%s DRIVE_FIXED %I64u %I64u %I64u\n",drive,availbytes,totbytes,totbytesfree);
334-
["DRIVE_FIXED", FreeBytesAvailableToCallerStr,
335-
_TotalNumberOfBytesStr, _TotalNumberOfFreeBytesStr] = string:tokens(DriveInfo, " "),
336-
list_to_integer(FreeBytesAvailableToCallerStr)
325+
try
326+
% Note: DriveInfoStr is in this format
327+
% "C:\\ DRIVE_FIXED 720441434112 1013310287872 720441434112\n"
328+
Lines = os_mon_sysinfo:get_disk_info(),
329+
[DriveInfoStr] = lists:filter(F, Lines),
330+
[DriveLetter, $:, $\\, $\s | DriveInfo] = DriveInfoStr,
331+
332+
% https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskfreespaceexa
333+
% lib/os_mon/c_src/win32sysinfo.c:
334+
% if (fpGetDiskFreeSpaceEx(drive,&availbytes,&totbytes,&totbytesfree)){
335+
% sprintf(answer,"%s DRIVE_FIXED %I64u %I64u %I64u\n",drive,availbytes,totbytes,totbytesfree);
336+
["DRIVE_FIXED", FreeBytesAvailableToCallerStr,
337+
_TotalNumberOfBytesStr, _TotalNumberOfFreeBytesStr] = string:tokens(DriveInfo, " "),
338+
list_to_integer(FreeBytesAvailableToCallerStr)
339+
catch _:{timeout, _}:_ ->
340+
%% could not compute the result
341+
'NaN';
342+
_:Reason:_ ->
343+
rabbit_log:warning("Free disk space monitoring failed to retrieve the amount of available space: ~p", [Reason]),
344+
%% could not compute the result
345+
'NaN'
346+
end
337347
end.
338348

339349
parse_free_unix(Str) ->

0 commit comments

Comments
 (0)