This repository was archived by the owner on Jan 15, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 411
Wait for debugger flag for .NET Core 2.0 / 2.1 implementation #130
Merged
mhart
merged 5 commits into
lambci:master
from
ndobryanskyy:feature/dotnet-debugging-slim
Dec 5, 2018
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
22a7e1f
Implement wait for debugger flag
ndobryanskyy 6daa6d3
Simplify flag finding. Remove environemnt variable.
ndobryanskyy c1c3611
Remove displaying process id, as it turned out to be not useful
ndobryanskyy 2200157
Revert default event body to empty object
ndobryanskyy b7cd42b
Update name of debugger flag to avoid future clashing
ndobryanskyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace MockLambdaRuntime | ||
| { | ||
| internal static class DebuggerExtensions | ||
| { | ||
| /// <summary> | ||
| /// Tries to wait for the debugger to attach by inspecting <see cref="Debugger.IsAttached"/> property in a loop. | ||
| /// </summary> | ||
| /// <param name="queryInterval"><see cref="TimeSpan"/> representing the frequency of inspection.</param> | ||
| /// <param name="timeout"><see cref="TimeSpan"/> representing the timeout for the operation.</param> | ||
| /// <returns><c>True</c> if debugger was attached, false if timeout occured.</returns> | ||
| public static bool TryWaitForAttaching(TimeSpan queryInterval, TimeSpan timeout) | ||
| { | ||
| var stopwatch = Stopwatch.StartNew(); | ||
|
|
||
| while (!Debugger.IsAttached) | ||
| { | ||
| if (stopwatch.Elapsed > timeout) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| Task.Delay(queryInterval).Wait(); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace MockLambdaRuntime | ||
| { | ||
| internal static class DebuggerExtensions | ||
| { | ||
| /// <summary> | ||
| /// Tries to wait for the debugger to attach by inspecting <see cref="Debugger.IsAttached"/> property in a loop. | ||
| /// </summary> | ||
| /// <param name="queryInterval"><see cref="TimeSpan"/> representing the frequency of inspection.</param> | ||
| /// <param name="timeout"><see cref="TimeSpan"/> representing the timeout for the operation.</param> | ||
| /// <returns><c>True</c> if debugger was attached, false if timeout occured.</returns> | ||
| public static bool TryWaitForAttaching(TimeSpan queryInterval, TimeSpan timeout) | ||
| { | ||
| var stopwatch = Stopwatch.StartNew(); | ||
|
|
||
| while (!Debugger.IsAttached) | ||
| { | ||
| if (stopwatch.Elapsed > timeout) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| Task.Delay(queryInterval).Wait(); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added
"\nUnhandled exception occured in runner:\n"to better constraint the exception origin for the user, while he is debugging. And outertry/catchblock is used to prevent user from hanging on unhandled exception from the runnner program.@mhart does it make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so – I think it'd be better to match the behaviour of the rest of the runtimes w/ regards to error output. So errors should look the same as they do on Lambda itself.
If it doesn't currently do that (it might not by the looks of it) – then we should change it so that it does 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't like the string, or how it behaves?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On this sample I've misused Lambda runner and got stuck on unhandled exception (default dotnet debugger behavior), that is why I have
try/catchblock around all the invocation.This sample was run on unmodified version of
lambci/lambda:dotnetcore2.1@mhart Did I make my point clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
--debugger-spin-wait?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, happy with that! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated according to comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I'm happy with that, feel free to update your SAM CLI PR 👍
I'll explore this PR more in the next couple of days, but I think the rest of it looks pretty good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, take your time @mhart