Ts3audiobot: API stops working.

Created on 8 Jan 2019  路  11Comments  路  Source: Splamy/TS3AudioBot

Describe the bug
Basically, the bug happens when my PHP script is making a request to the TS3AB API and while doing it, I exit out of my script.

To Reproduce
Make a script that would connect to the TS3AB API and make a simple request; it can even be like getting bot list or instance info. Then try to turn off and on the script a few times and you should see in your debug window of TS3AB "WebServer has closed".

Version
Version: 0.9.1
Branch: master
CommitHash: 673e0afb19424101304e515ec2d5d15ccf961a3f

Platform
Ubuntu 16.04

Log

05:11:01| INFO| xx.xx.xxx.xx Requested: /api/bot/use/0/(/bot/info
05:11:03| INFO| xx.xx.xxx.xx Requested: /api/bot/use/0/(/bot/info
05:11:04| INFO| xx.xx.xxx.xx Requested: /api/bot/use/0/(/bot/info
05:11:06| INFO| xx.xx.xxx.xx Requested: /api/bot/use/0/(/bot/info
05:11:07| INFO| xx.xx.xxx.xx Requested: /api/bot/use/0/(/bot/info
05:11:08| INFO| xx.xx.xxx.xx Requested: /api/bot/use/0/(/bot/info
05:11:09| INFO| xx.xx.xxx.xx Requested: /api/bot/use/0/(/bot/info
05:11:10| INFO| WebServer has closed
System.Net.HttpListenerException (0x80004005): Listener closed
  at System.Net.ListenerAsyncResult.GetContext () [0x0001c] in <eeec8e88b1fc462e84ade7bf334d0c97>:0 
  at System.Net.HttpListener.EndGetContext (System.IAsyncResult asyncResult) [0x00099] in <eeec8e88b1fc462e84ade7bf334d0c97>:0 
  at System.Net.HttpListener.GetContext () [0x0002d] in <eeec8e88b1fc462e84ade7bf334d0c97>:0 
  at TS3AudioBot.Web.WebServer.EnterWebLoop () [0x0004e] in <cbb5379733f744b5a926811d68f3b8b4>:0 
03:23:39| INFO|WebServer.EnterWebLoop WebServer has closed

Then after this, nothing from the API shows if I request anything else.

If fixing it is not possible, I think relaunching web-server would be fine I guess but I don't think that's a "professional" way of fixing it.

bug

All 11 comments

I was able to reproduce a (similar?) error with while true; curl 127.0.0.1:8180/api/bot/list; end and pressing Ctrl+C at some point.

this created

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.HttpListenerResponse'.
   at System.Net.HttpListenerResponse.CheckDisposed()
   at System.Net.HttpListenerResponse.set_StatusCode(Int32 value)
   at TS3AudioBot.Web.Api.WebApi.ProcessApiV1Call(Uri uri, HttpListenerResponse response, InvokerData invoker) in /home/TS3AudioBot/TS3AudioBot/Web/Api/WebApi.cs:line 122
   at TS3AudioBot.Web.Api.WebApi.DispatchCall(HttpListenerContext context) in /home/TS3AudioBot/TS3AudioBot/Web/Api/WebApi.cs:line 76
   at TS3AudioBot.Web.WebServer.EnterWebLoop() in /home/TS3AudioBot/TS3AudioBot/Web/WebServer.cs:line 183

The exception gets catched at TS3AudioBot/Web/WebServer.cs#L196 and closes the webserver, so we just have to continue the webserver instead of breaking.

No, don't continue there; thats the only exit point of the loop. Usually when closing the webserver, the next call in the loop while (webListener?.IsListening ?? false) will already cause an ObjectDisposedException.

@Splamy do you know when you might have it fixed?

Btw. I tried my own little fix which was after this, "Log.Info("WebServer has closed - Restarting now.");"
I put function"EnterWebLoop();" and it seems to work. Results:

03:08:13| INFO| xx.xx.xxx.xx Requested: /api/bot/use/0/(/bot/info
03:08:14| INFO| WebServer has closed - Starting again.
03:08:16| INFO| xx.xx.xxx.xx Requested: /api/bot/use/0/(/bot/info
03:08:16| INFO| WebServer has closed - Starting again.
03:08:19| INFO| xx.xx.xxx.xx Requested: /api/bot/use/0/(/bot/info

I had to learn for a test today; so since that's done i'll try to look today or tomorrow into it when i'm not too tired

@Splamy I hope your test went well.
Not sure if you saw it in my comment, the exception is thrown because the HttpListenerResponse is null, not the HttpListener, so the server itself should still be working fine :).

@Flakebi oh, indeed

I pushed a fix to develop, you can try and see if it works.

@Splamy Yes, I believe it does.

22:29:55| INFO| xx.xxx.xx.xxx Requested: /api/bot/list
22:29:56| INFO| xx.xxx.xx.xxx Requested: /api/bot/list
22:29:56| INFO| xx.xxx.xx.xxx Requested: /api/bot/list
22:29:56|ERROR| Unexpected command error
22:29:56|ERROR| Failed to respond to HTTP request.
22:29:56| INFO| xx.xxx.xx.xxx Requested: /api/bot/list
22:29:57| INFO| xx.xxx.xx.xxx Requested: /api/bot/list

That's good to hear.
Btw, could you give me the two stacktraces which should be in the log for tjose two errors. I just wan't to see if it's something interesting

@Splamy

23:41:44|ERROR|WebApi.ProcessApiV1Call Unexpected command error
System.IO.IOException: Unable to write data to the transport connection: The socket has been shut down. ---> System.Net.Sockets.SocketException: The socket has been shut down
  at System.Net.Sockets.Socket.Send (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags) [0x00016] in <eeec8e88b1fc462e84ade7bf334d0c97>:0 
  at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x0009b] in <eeec8e88b1fc462e84ade7bf334d0c97>:0 
   --- End of inner exception stack trace ---
  at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x000e2] in <eeec8e88b1fc462e84ade7bf334d0c97>:0 
  at System.Net.ResponseStream.InternalWrite (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x0001b] in <eeec8e88b1fc462e84ade7bf334d0c97>:0 
  at System.Net.ResponseStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x000db] in <eeec8e88b1fc462e84ade7bf334d0c97>:0 
  at System.IO.StreamWriter.Flush (System.Boolean flushStream, System.Boolean flushEncoder) [0x0007e] in <7b0d87324cab49bf96eac679025e77d1>:0 
  at System.IO.StreamWriter.Dispose (System.Boolean disposing) [0x00022] in <7b0d87324cab49bf96eac679025e77d1>:0 
  at System.IO.TextWriter.Dispose () [0x00000] in <7b0d87324cab49bf96eac679025e77d1>:0 
  at TS3AudioBot.Web.Api.WebApi.ProcessApiV1Call (System.Uri uri, System.Net.HttpListenerResponse response, TS3AudioBot.InvokerData invoker) [0x000ef] in <253b997b22cd4382b35cf7350afe7d7c>:0 
23:41:44|ERROR|WebApi.ProcessApiV1Call Failed to respond to HTTP request.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.HttpListenerResponse'.
  at System.Net.HttpListenerResponse.set_StatusCode (System.Int32 value) [0x00013] in <eeec8e88b1fc462e84ade7bf334d0c97>:0 
  at TS3AudioBot.Web.Api.WebApi.ProcessApiV1Call (System.Uri uri, System.Net.HttpListenerResponse response, TS3AudioBot.InvokerData invoker) [0x0014b] in <253b997b22cd4382b35cf7350afe7d7c>:0 

Yeah, seems fine.
I'll close this if there's nothing else

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Splamy picture Splamy  路  4Comments

lgund picture lgund  路  3Comments

Edith445544986 picture Edith445544986  路  4Comments

GooG2e picture GooG2e  路  6Comments

SuspiciousActivity picture SuspiciousActivity  路  6Comments