New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PuppeteerException("Response body is unavailable for redirect responses") throw outside application flow #891

Open
brianfeucht opened this Issue Feb 1, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@brianfeucht
Copy link

brianfeucht commented Feb 1, 2019

Description

I'm running into an issue where Puppeteer is throwing exceptions outside of the flow of my application. This means they are getting raised via UnobservedTaskException. This code is running completely and a screenshot is being returned.

Is there a way I can force these exceptions to be raised in my code or a way I can suppress them?

Details of exception being thrown:

A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Response body is unavailable for redirect responses)
"errorType": "PuppeteerException",
"errorMessage": "Response body is unavailable for redirect responses"

Complete minimal example reproducing the issue

private static readonly ScreenshotOptions screenshotOptions = new ScreenshotOptions()
{
	FullPage = true,
	Type = ScreenshotType.Png,
};

private static readonly NavigationOptions navigationOptions = new NavigationOptions
{
	WaitUntil = new[]
	{
		WaitUntilNavigation.Load,
		WaitUntilNavigation.DOMContentLoaded,
		WaitUntilNavigation.Networkidle2
	}
};
using (var browser = await browserLauncher.LaunchAsync())
using (var page = await browser.NewPageAsync())
{
	var response = await page.GoToAsync(url, navigationOptions);
	
	page.Viewport.Width = width;
	var screenshot =  await page.ScreenshotDataAsync(screenshotOptions);
	await browser.CloseAsync();
	return screenshot;
}

Expected behavior:

Exceptions to be suppressed or thrown in my application context

Actual behavior:

Exceptions bubbling up threw UnobservedTaskException during finalization

Versions

  • Which version of PuppeteerSharp are you using?
    1.11.2
  • Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.0.
    netcoreapp2.1 on AWS Lambda

Additional Information

Using this library on AWS Lambda: https://github.com/litmus/HeadlessChromium.Puppeteer.Lambda.Dotnet

@kblok kblok added the bug label Feb 1, 2019

@kblok

This comment has been minimized.

Copy link
Owner

kblok commented Feb 1, 2019

That exception comes from the NetworkManager. We are just faulting the TaskCompletionSource.

It seems that your setup doesn't like that. I will try to see if I can listen to TaskScheduler.UnobservedTaskException and raise exceptions from the tests.

Is it something that is blocking you? Do you have a workaround? If it's blocking you I can release a hotfix, if not we could wait to v1.12.

Thank you for your contribution :)

@brianfeucht

This comment has been minimized.

Copy link
Author

brianfeucht commented Feb 1, 2019

Nothing blocking.

Lambda is filling CloudWatch with errors as it appears to hook into this event handler. I think I can handle those UnobservedTaskException before Lambda does and prevent it from logging them as a work around.

@brianfeucht

This comment has been minimized.

Copy link
Author

brianfeucht commented Feb 1, 2019

I'm not able to prevent Lambda from logging this to CloudWatch. Their event handler fires before the one I'm registering, so all this did was create duplicate log messages.

TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
	e.SetObserved();
	logger.Warning(e.Exception, "Unhandled exception in lambda function");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment