Dispose methods and finally blocks don't throw exceptions.#767
Dispose methods and finally blocks don't throw exceptions.#767aidmsu wants to merge 4 commits intoHangfireIO:devfrom aidmsu:unthrowable-dispose
Conversation
Current coverage is 67.73% (diff: 68.75%)
|
odinserj
left a comment
There was a problem hiding this comment.
Thanks for submitting this PR, I've added some comments.
| /// <param name="properties"></param> | ||
| /// <param name="options"></param> | ||
| public BackgroundProcessingServer( | ||
| [NotNull] JobStorage storage, |
There was a problem hiding this comment.
First, please remove this change...
| [NotNull] JobStorage storage, | ||
| [NotNull] JobStorage storage, | ||
| [NotNull] IEnumerable<IBackgroundProcess> processes, | ||
| [NotNull] IDictionary<string, object> properties, |
|
|
||
| var context = new BackgroundProcessContext( | ||
| GetGloballyUniqueServerId(), | ||
| GetGloballyUniqueServerId(), |
|
|
||
| private const string DistributedLockKey = "locks:expirationmanager"; | ||
| private static readonly TimeSpan DefaultLockTimeout = TimeSpan.FromMinutes(5); | ||
| // Note, that lock escalation may also happen during the cascade deletions for | ||
| // State (3-5 rows/job usually) and JobParameters (2-3 rows/job usually) tables. | ||
| private const int NumberOfRecordsInSinglePass = 1000; | ||
| if ((shutdownTimeout < TimeSpan.Zero && shutdownTimeout != Timeout.InfiniteTimeSpan) || | ||
| shutdownTimeout.TotalMilliseconds > Int32.MaxValue) | ||
| { | ||
| Logger.Warn($@"ShutdownTimeout equals {_options.ShutdownTimeout.Milliseconds} milliseconds and it't incorret. |
| catch (Exception ex) | ||
| { | ||
| connection.RemoveServer(context.ServerId); | ||
| Logger.WarnException($@"Couldn't remove server {context.ServerId}. The server can be displayed on 'Server' page of Dashboard for a while. |
There was a problem hiding this comment.
The server phrase duplication, you can replace it with the , but it won't perform.
| // Timer callback may be invoked after the Dispose method call, | ||
| // so we are using lock to avoid unsynchronized calls. | ||
|
|
||
| try |
There was a problem hiding this comment.
Why did you remove the try-catch statement? The absence of the SqlException does not guarantee the absence of any other exceptions, like ThreadAbortedException, etc. The method can still throw, and we still should release the acquired connection.
|
|
||
| internal static void Release(IDbConnection connection, string resource) | ||
| { | ||
| var couldNotReleaseLockMessageTemplate = $@"Could not release a lock on the resource '{resource}'. {0} |
There was a problem hiding this comment.
Please use single line for log messages.
| } | ||
| catch (SqlException ex) | ||
| { | ||
| Logger.WarnException(string.Format(couldNotReleaseLockMessageTemplate, string.Empty), ex); |
There was a problem hiding this comment.
string.Empty may cause extra spaces in log message.
2183dda to
5ab7e98
Compare
Dispose methods and finally blocks don't throw any exceptions. Instead exceptions are caught and logged.