Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Stop Listener when disposed (#104) #105

Merged
merged 3 commits into from
Feb 11, 2022
Merged

Stop Listener when disposed (#104) #105

merged 3 commits into from
Feb 11, 2022

Conversation

alrod
Copy link
Member

@alrod alrod commented Feb 3, 2022

Address issue detailed in #104

Also as part of the PR I added the track2 port (6c9df8b) which helps with Dispose_Calls_StopAsync test and CRIs invetigations in general:
Azure/azure-sdk-for-net@bad9b85

@alrod alrod requested a review from brettsam February 3, 2022 02:28
@alrod alrod force-pushed the alrod/fix-disposed-race branch from f5cc60e to 8a1fd20 Compare February 3, 2022 20:36
@alrod alrod requested a review from brettsam February 4, 2022 19:00
brettsam
brettsam previously approved these changes Feb 4, 2022
Copy link
Member

@brettsam brettsam left a comment

Choose a reason for hiding this comment

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

This looks okay to me -- maybe @sidkri wants to double-check as well?

// Host for the EventHubListener have beed disposed,
// the invocation(s) can be uncompleted in this case
// and we do not to checkpoint to avoid possible data lose
_logger.LogDebug(GetOperationDetails(context, "SkipCheckpointDueHostDisposed"));
Copy link
Member

Choose a reason for hiding this comment

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

nit: SkipCheckpointDueToHostDisposed

{
await CheckpointAsync(context);
// Host for the EventHubListener have beed disposed,
// the invocation(s) can be uncompleted in this case
Copy link
Member

Choose a reason for hiding this comment

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

Rather than saying "uncompleted", could you comment that we expect function invocations to fail before reaching customer code and so the checkpoint should not be advanced?

@@ -308,7 +308,7 @@ public async Task ProcessEvents_SingleDispatch_SystemPropertiesAndApplicationPro
var loggerMock = new Mock<ILogger>();
var executor = new Mock<ITriggeredFunctionExecutor>(MockBehavior.Strict);
executor.Setup(p => p.TryExecuteAsync(It.IsAny<TriggeredFunctionData>(), It.IsAny<CancellationToken>())).ReturnsAsync(new FunctionResult(true));
var eventProcessor = new EventHubListener.EventProcessor(options, executor.Object, loggerMock.Object, true, checkpointer.Object);
var eventProcessor = new EventHubListener.EventProcessor(options, executor.Object, loggerMock.Object, true, new Mock<EventHubListener.IDisposed>().Object, checkpointer.Object);
Copy link
Member

Choose a reason for hiding this comment

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

nit: indenting

@@ -88,9 +91,11 @@ public async Task StopAsync(CancellationToken cancellationToken)
_started = false;
Copy link
Member

Choose a reason for hiding this comment

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

Is there any possibility of StopAsync() getting called concurrently ? Not sure what happens if UnregisterEventProcessorAsync() is called concurrently. We may want to add a lock around line this call.

Copy link
Member

@sidkri sidkri left a comment

Choose a reason for hiding this comment

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

Requesting a discussion around my comment on line 75 of EventHubListener before merging this PR.

@sidkri sidkri linked an issue Feb 9, 2022 that may be closed by this pull request
@alrod alrod force-pushed the alrod/fix-disposed-race branch from 8a1fd20 to 2787f67 Compare February 10, 2022 22:26
@alrod alrod requested review from brettsam and sidkri February 10, 2022 22:28
@alrod alrod force-pushed the alrod/fix-disposed-race branch from 2787f67 to 6d84ee8 Compare February 10, 2022 22:30
@alrod alrod force-pushed the alrod/fix-disposed-race branch from 6c9df8b to 46b283d Compare February 11, 2022 00:54
liliankasem
liliankasem previously approved these changes Feb 11, 2022
private bool _started;
private string _details;
Copy link
Member

Choose a reason for hiding this comment

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

readonly?

}
_started = false;

_logger.LogDebug($"EventHub listener stopped ({_details})");
Copy link
Member

Choose a reason for hiding this comment

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

Move this within the if (_started) block so we don't log on a no-op call to StopAsync() (e.g. when StopAsync is called for the second time)

Copy link
Member

@sidkri sidkri Feb 11, 2022

Choose a reason for hiding this comment

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

Alternately, its fine if we want to show how many times StopAsync() was called. But in this case, we may want to log "stopped" in the if (_started) block and a different log statement in the else condition to indicate no action was needed as the listener is already stopped. This will give us better insights when debugging issues.

string functionId = "FunctionId";
string eventHubName = "EventHubName";
string consumerGroup = "ConsumerGroup";
var storageUri = new Uri("https://eventhubsteststorageaccount.blob.core.windows.net/");
Copy link
Member

Choose a reason for hiding this comment

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

not used, hard coded on line 246 instead. consider moving this to a class member as the same URI is used in GetMonitor_ReturnsExpectedValue() as well.

sidkri
sidkri previously approved these changes Feb 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop Listener when disposed
5 participants