titanium-web-proxy icon indicating copy to clipboard operation
titanium-web-proxy copied to clipboard

Exception when calling SessionEventArgs.GetResponseBody()

Open antrv opened this issue 6 years ago • 30 comments
trafficstars

Hello,

I get the following exception sometimes when SessionEventArgs.GetResponseBody is called. I have not figured out the reasons yet. Maybe anyone knows about this.

Thanks

System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at Titanium.Web.Proxy.EventArguments.LimitedStream.getNextChunk() at Titanium.Web.Proxy.EventArguments.LimitedStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.IO.Stream.<>c.<BeginReadInternal>b__39_0(Object ) at System.Threading.Tasks.Task1.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.IO.Stream.EndRead(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncTrimPromise1.Complete(TInstance thisRef, Func3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Titanium.Web.Proxy.EventArguments.LimitedStream.<Finish>d__22.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Titanium.Web.Proxy.EventArguments.SessionEventArgs.<copyBodyAsync>d__22.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Titanium.Web.Proxy.EventArguments.SessionEventArgs.<CopyResponseBodyAsync>d__21.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Titanium.Web.Proxy.EventArguments.SessionEventArgs.<readBodyAsync>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Titanium.Web.Proxy.EventArguments.SessionEventArgs.<readResponseBodyAsync>d__17.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Titanium.Web.Proxy.EventArguments.SessionEventArgs.<GetResponseBody>d__28.MoveNext()

antrv avatar Jan 30 '19 09:01 antrv

The call stack tells that the chunked response from the server was not in correct format. It tried to parse the next chunk length from the header (to an integer) but failed due to bad format.

justcoding121 avatar Jan 31 '19 16:01 justcoding121

Is that a public website? Could you tell me please the url? (And other information that i have to do on that website)

I'd like to check the response received from the server.

honfika avatar Apr 25 '19 18:04 honfika

Hi! Yes, it is https://youtube.com, I don't remember the exact video url.

antrv avatar Apr 26 '19 08:04 antrv

Actually this exception happens very often in about 1/3 of all requests.

antrv avatar Apr 26 '19 08:04 antrv

Could you tell me what locale settings do you have? Finnish? fi-FI?

honfika avatar Apr 26 '19 09:04 honfika

I have browsers with 2 configured locales: en-US and ru-RU.

antrv avatar Apr 26 '19 09:04 antrv

The same issue. I can't fix it about 2 hours( So I'm leaving, it's so unstable crap. Is there any alternatives for C#?

grandsilence avatar Jul 11 '19 22:07 grandsilence

@grandsilence This project is no longer maintained, as I don't have time to contribute and other contributors are not active. Sorry, but you may check out Fiddlercore. (That's the only c# alternative I know, but last time I checked it was not absolutely free).

justcoding121 avatar Jul 11 '19 22:07 justcoding121

@justcoding121 Sad to hear. Thanks for the reply. I decided to give up C# in network things. Who is interested https://github.com/elazarl/goproxy successfully solved the problem of overwriting traffic.

grandsilence avatar Jul 11 '19 22:07 grandsilence

I'd fix this issue, but really cannot reproduce it :(

honfika avatar Jul 13 '19 06:07 honfika

@justcoding121 If you do not have time to contribute, could you please enable again commiting to the master branch? For me it would be easier to fix bugs directly there. I'm also not so active, but I'd like to fix some small issues.

And I think it is time to drop the NET4.5 support, upgrade to NET461, which is netstandrad 2.0. In this case a lot of #if NET45 conditions could be removed.

(Maybe release a last 4.5 version from the current master, then remove it.)

honfika avatar Jul 13 '19 08:07 honfika

You should be able to merge PR without any approval. Possibly also commit directly to master. Did you try? @honfika

justcoding121 avatar Jul 14 '19 13:07 justcoding121

You can do whatever changes you think would be needed. No need for my input.

justcoding121 avatar Jul 14 '19 13:07 justcoding121

@antrv, @grandsilence: Please try the latest beta build. It should throw a new exception which maybe helps us to fix the issue: Invalid chunk length: '{chunkHead}'

When you get this exception message, please let me know what is between the quotes.

honfika avatar Jul 15 '19 13:07 honfika

@justcoding121 I'll try the direct push soon. Thank you.

honfika avatar Jul 15 '19 13:07 honfika

@honfika If you are up to maintaining the project, feel free to remove the notice I put on the readme. Thanks.

justcoding121 avatar Jul 15 '19 20:07 justcoding121

@honfika Are you planning to maintain this project and remove the note from the readme file? Thanks.

mgerenst avatar Aug 02 '19 09:08 mgerenst

@mgerenst I'm trying to fix some smaller bugs, trying to improve the http/2 support.

What I don't have:

  • Linux/Mono
  • Mac
  • Windows 8.1 or earlier
  • Other IDE than VS 2019

So I'll give smaller priority for those issues, but PR's are welcome:)

I'd like to fix this issue, but I can"t reproduce it, so the only thing I could do is adding a better exception handling, another exception message, which could help to solve the problem.

Why do you asking?

honfika avatar Aug 02 '19 20:08 honfika

I'll be happy to help with MAC, anyway my question is not for this issue specific and more in general are you taking ownership (or intend to support) this project?

mgerenst avatar Aug 04 '19 11:08 mgerenst

Yes, I'd like to support this project.

honfika avatar Aug 05 '19 17:08 honfika

@honfika Thanks for your support.

@mgerenst I've removed the disclaimer https://github.com/justcoding121/Titanium-Web-Proxy/commit/c7e34cc76e468fa6f1984b543a5f4341b7c91f52

justcoding121 avatar Aug 07 '19 12:08 justcoding121

I've discovered a new, reliable way of triggering this issue. Stream downloads. I added some caching code to cache my steam-downloads locally on my network. It seems almost every server response causes the exception. So for the sake of an easily reproducible test case, it seems to do the job.

ninlilizi avatar Feb 02 '20 21:02 ninlilizi

What is the exception message?

honfika avatar Feb 02 '20 21:02 honfika

{System.Collections.ListDictionaryInternal} called from GetResponseBody()

The exception generated is: _COMPlusExceptionCode | -532462766 | int

Debug trace here

ninlilizi avatar Feb 02 '20 22:02 ninlilizi

I'll throw in the response headers too while I'm here, as likely pertinent

[0] {Server: nginx/1.17.6}
[1] {Date: Sun, 02 Feb 2020 22:34:33 GMT}
[2] {Content-Type: application/x-steam-chunk}
[3] {Content-Length: 1062224}
[4] {Connection: keep-alive}
[5] {last-modified: Sun, 22 Dec 2019 19:19:25 GMT}
[6] {x-content-crc: 4112437831}
[7] {x-content-sha: 83679326a116485838dac8602d760571cd8be8bd}
[8] {Content-MD5: +JawS68Mlzrz+Kwt4YViMw==}
[9] {Expires: Thu, 27 Feb 2020 19:19:25 GMT}
[10] {X-Cache-Status: HIT}

ninlilizi avatar Feb 02 '20 22:02 ninlilizi

Hmm, I think you coped wrong screnshot.. you sould attach the exception which was thrown... in the screenshot you are showing something in the watch window.

honfika avatar Feb 02 '20 23:02 honfika

I tried to download a game from Stream, but it worked.

Are you sure that your exception is "System.FormatException: Input string was not in a correct format"?

honfika avatar Feb 02 '20 23:02 honfika

Yes, I am.... Sorry, I'm being less than helpful. Since installing the Titanium package I've not been receiving stack traces in the console and having to poke around just to get the actual exceptions being thrown.

Generated from calling byte[] derp = $object.GetResponseBody in onResponse event handler.

I've never in my life known of a package to disable stack traces like that before and am somewhat flummoxed in figuring out how to turn them back on again.

I'll provide more information when I've made vs a little more cooperative.

ninlilizi avatar Feb 02 '20 23:02 ninlilizi

Ok, I think the real story here if my visual studio exception handling is somehow broken.

My actual exception was caused by a null ptr in a header. Testing around that fixed that unrelated issue.

I'm really sorry for wasting your time in this way.

ninlilizi avatar Feb 02 '20 23:02 ninlilizi

So in my case the issue went away when I switched from AfterResponse event to BeforeResponse event.

Zaczero avatar Aug 23 '20 05:08 Zaczero