Skip to content

Dispose methods and finally blocks don't throw exceptions.#767

Open
aidmsu wants to merge 4 commits intoHangfireIO:devfrom
aidmsu:unthrowable-dispose
Open

Dispose methods and finally blocks don't throw exceptions.#767
aidmsu wants to merge 4 commits intoHangfireIO:devfrom
aidmsu:unthrowable-dispose

Conversation

@aidmsu
Copy link
Copy Markdown
Contributor

@aidmsu aidmsu commented Dec 19, 2016

Dispose methods and finally blocks don't throw any exceptions. Instead exceptions are caught and logged.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Dec 19, 2016

Current coverage is 67.73% (diff: 68.75%)

Merging #767 into dev will increase coverage by 0.03%

Diff Coverage File Path
••••• 55% ...c/Hangfire.Core/Server/BackgroundProcessingServer.cs
••••••••• 91% src/Hangfire.SqlServer/SqlServerDistributedLock.cs

Powered by Codecov. Last update b4cdf1c...20c3224

Copy link
Copy Markdown
Member

@odinserj odinserj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this PR, I've added some comments.

/// <param name="properties"></param>
/// <param name="options"></param>
public BackgroundProcessingServer(
[NotNull] JobStorage storage,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, please remove this change...

[NotNull] JobStorage storage,
[NotNull] JobStorage storage,
[NotNull] IEnumerable<IBackgroundProcess> processes,
[NotNull] IDictionary<string, object> properties,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..., this...


var context = new BackgroundProcessContext(
GetGloballyUniqueServerId(),
GetGloballyUniqueServerId(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..., this...


private const string DistributedLockKey = "locks:expirationmanager";
private static readonly TimeSpan DefaultLockTimeout = TimeSpan.FromMinutes(5);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..., this...

// 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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and this ☺️

if ((shutdownTimeout < TimeSpan.Zero && shutdownTimeout != Timeout.InfiniteTimeSpan) ||
shutdownTimeout.TotalMilliseconds > Int32.MaxValue)
{
Logger.Warn($@"ShutdownTimeout equals {_options.ShutdownTimeout.Milliseconds} milliseconds and it't incorret.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo incorretincorrect.

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use single line for log messages.

}
catch (SqlException ex)
{
Logger.WarnException(string.Format(couldNotReleaseLockMessageTemplate, string.Empty), ex);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string.Empty may cause extra spaces in log message.

@odinserj odinserj force-pushed the dev branch 2 times, most recently from 2183dda to 5ab7e98 Compare March 5, 2018 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants