Raised This Month: $12 Target: $400
 3% 

Klippy's Webserver


Post New Thread Reply   
 
Thread Tools Display Modes
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 11-14-2016 , 16:06   Re: Klippy's Webserver
Reply With Quote #11

Quote:
Originally Posted by WildCard65 View Post
I may mess around with your project and see if I can setup AMBuild for it for both Windows and Linux.
Yay thanks. For some reason I was always avoiding AMBuild, smh.
klippy is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 11-15-2016 , 07:08   Re: Klippy's Webserver
Reply With Quote #12

The module is pretty impressive. Do you ever plan on completing it? Most of it seems to work from what I've tested.

1. It prints "[META] ERROR: Plugin didn't set meta_result: webserver_amxx.dll:ServerActivate()" in the server console.
2
Code:
WS_QueueResponse(WSConnection: connection, WSStatusCode: status, WSResponse: response);
-->
Code:
WS_QueueResponse(WSConnection: connection, status, WSResponse: response);

3. Something very strange is how using the same exact code produces an error in one plugin and crashes another.

Code:
#include <amxmodx> #include <webserver> public plugin_init() {     WS_RegisterRequestCallback("home", "OnWebServerHome");     WS_RegisterRequestCallback("motd", "OnWebServerHome"); } public OnWebServerHome(WSConnection:Connection, const Method[], const URL[]) {     static Threshold;     server_print("%d", Threshold++);     new WSResponse:WS_FILERESPONSE = WS_CreateFileResponse("motd.txt");     new WS_RETURN = WS_QueueResponse(Connection, WS_StatusCode_OK, WS_FILERESPONSE);     WS_DestroyResponse(WS_FILERESPONSE);     return WS_RETURN; }

[WEBSERVER] Invalid handle -1
[AMXX] Displaying debug trace (plugin "test.amxx", version "unknown")
[AMXX] Run time error 10: native error (native "WS_QueueResponse")
[AMXX] [0] test.sma::OnWebServerHome (line 17)

When I spam refresh through my web browser I get that error at random points. That function can get called over 100 times without giving out any errors, then it errors out twice within 10 calls. It's random. In another plugin where I have the same exact code among other functions that are not related to webserver, the server crashes rather when I spam refresh, no errors just crashing. Any idea what might be causing this or what kind of tests I can do to try to figure out what's causing this?
PartialCloning is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 11-15-2016 , 08:01   Re: Klippy's Webserver
Reply With Quote #13

Quote:
Originally Posted by PartialCloning View Post
The module is pretty impressive.
Thanks :^)

Quote:
Do you ever plan on completing it? Most of it seems to work from what I've tested.
Probably. I know that POST request processing doesn't work properly (wasn't implemented actually, requires some extra code) and that I have to rework how handles are allocated(free handles are not re-used), not sure if there is anything else.

Quote:
1. It prints "[META] ERROR: Plugin didn't set meta_result: webserver_amxx.dll:ServerActivate()" in the server console.
Forgot to add RETURN_META, fixed. It's strange I haven't noticed that one.

Quote:
2
Code:
WS_QueueResponse(WSConnection: connection, WSStatusCode: status, WSResponse: response);
-->
Code:
WS_QueueResponse(WSConnection: connection, status, WSResponse: response);
I probably wanted to create a WStatusCode enumeration at one point then forgot. I think removing the tag would be wise as someone may want to put a status code other than pre-defined ones.

Quote:
3. Something very strange is how using the same exact code produces an error in one plugin and crashes another.

Code:
#include <amxmodx> #include <webserver> public plugin_init() {     WS_RegisterRequestCallback("home", "OnWebServerHome");     WS_RegisterRequestCallback("motd", "OnWebServerHome"); } public OnWebServerHome(WSConnection:Connection, const Method[], const URL[]) {     static Threshold;     server_print("%d", Threshold++);     new WSResponse:WS_FILERESPONSE = WS_CreateFileResponse("motd.txt");     new WS_RETURN = WS_QueueResponse(Connection, WS_StatusCode_OK, WS_FILERESPONSE);     WS_DestroyResponse(WS_FILERESPONSE);     return WS_RETURN; }

[WEBSERVER] Invalid handle -1
[AMXX] Displaying debug trace (plugin "test.amxx", version "unknown")
[AMXX] Run time error 10: native error (native "WS_QueueResponse")
[AMXX] [0] test.sma::OnWebServerHome (line 17)

When I spam refresh through my web browser I get that error at random points. That function can get called over 100 times without giving out any errors, then it errors out twice within 10 calls. It's random. In another plugin where I have the same exact code among other functions that are not related to webserver, the server crashes rather when I spam refresh, no errors just crashing. Any idea what might be causing this or what kind of tests I can do to try to figure out what's causing this?
Probably this piece of code failed:
PHP Code:
int fd openfd(MF_BuildPathname("%s"path), FDMODE);
if (
fd 0) {
    return -
1;

meaning that it couldn't open the file for reading. Why? I have no idea, but spamming might have to do something with it. I guess you can check if WS_CreateFileResponse() return value is -1 then do something else, maybe display 404.

I attached a new one with the first error fixed. Also, now when the file opening fails it will print the error code in the console - that will help us debug the native.
Attached Files
File Type: dll webserver_amxx.dll (76.5 KB, 91 views)
klippy is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 11-17-2016 , 02:00   Re: Klippy's Webserver
Reply With Quote #14

WS_CreateFileResponse was returning -1 when spamming refresh. "[WEBSERVER] Couldn't open file for reading, errno: 2"

The server still crashes a lot randomly while spamming refresh. Even if I have nothing running in the call back. It's as if the spamming slows down the server to the point where other modules malfunction (specifically on heavy forwards so I used server_frame to test it) causing the server to crash.

Code:
#include <amxmodx> #include <webserver> public plugin_init() {     WS_RegisterRequestCallback("home", "OnWebServerHome");     WS_RegisterRequestCallback("motd", "OnWebServerHome"); } public OnWebServerHome(WSConnection:Connection, const Method[], const URL[]) {     static ThresHold;     server_print("%d", ThresHold++);     return MHD_NO; } public server_frame() {     static i;     for(i = 0; i <= MaxClients; i++)         if(is_user_connected(i) && !is_user_alive(i))             continue; }

Join the server or have bots join the server then hold down ctrl + r (refresh) and it'll crash the server after 5-20 seconds.

Sometimes I even get errors such as:

String formatted incorrectly - parameter 2 (total 0)
[AMXX] Run time error 5: memory access
[AMXX] [0] test.sma::server_frame (line 21)

Line 21 is for(i = 0; i <= MaxClients; i++)??


Displaying debug trace (plugin "test.amxx", version "unknown")
[AMXX] Run time error 5: memory access
[AMXX] [0] test.sma::OnWebServerHome (line 13)

Line 13 is server_print("%d", ThresHold++);

Last edited by PartialCloning; 11-17-2016 at 02:02.
PartialCloning is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 11-17-2016 , 08:58   Re: Klippy's Webserver
Reply With Quote #15

errno 2 is ENOENT, which means it couldn't find your file. Why? No idea, but basically it would be wise to check if it returned -1 anyway.
I'll add more checks and debug messages to it later today. Thanks for testing out the module. =)

EDIT:
Actually it may be possible that the "incoming request" function is called from another thread while the current callback is executing already (Pawn isn't multi-threaded and it very well breaks when you try to multi-thread it). Maybe just creating an event queue would solve it. I'll check later, I'm currently busy.

EDIT:
I may as well switch to libwebsockets once. Seems like a better option, Asherkin recommended it to me a while ago while I was working on that module.

Last edited by klippy; 11-17-2016 at 14:34.
klippy is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 11-27-2016 , 03:32   Re: Klippy's Webserver
Reply With Quote #16

Is it a work in progress that might be done soon or could it take a while, if ever, for you to be interested in working on it again?
PartialCloning is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 11-28-2016 , 13:58   Re: Klippy's Webserver
Reply With Quote #17

Quote:
Originally Posted by PartialCloning View Post
Is it a work in progress that might be done soon or could it take a while, if ever, for you to be interested in working on it again?
As the first step towards it, I added AMBuild and made compiling on both Linux and Windows as easy as running a few commands. I'll update README to reflect new changes.
https://github.com/rsKliPPy/webserver_amxx

I think I'll just try to finish it, wish me luck.

EDIT:
Also, I couldn't reproduce your issue on Windows. I held the refresh button for just over 1000 requests and it didn't bug out once.

Last edited by klippy; 11-28-2016 at 17:39.
klippy is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 11-29-2016 , 08:09   Re: Klippy's Webserver
Reply With Quote #18

Were there any players in the server when you refreshed? Or at least bots?
PartialCloning is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 11-29-2016 , 08:11   Re: Klippy's Webserver
Reply With Quote #19

No, just me. It was a listen server.

Last edited by klippy; 11-29-2016 at 08:11.
klippy is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 11-29-2016 , 09:33   Re: Klippy's Webserver
Reply With Quote #20

Code:
#include <amxmodx> #include <engine> #include <fakemeta> #include <webserver> public plugin_init() {     WS_RegisterRequestCallback("home", "OnWebServerHome");     WS_RegisterRequestCallback("motd", "OnWebServerHome"); } public OnWebServerHome(WSConnection:Connection, const Method[], const URL[]) {     static ThresHold;     server_print("%d", ThresHold++);     return MHD_NO; } public server_frame() {     static i, Index, Body, Classname[64];     for(i = 1; i <= MaxClients; i++)     {         if(!is_user_connected(i))             continue;         get_user_aiming(i, Index, Body, 6000);         pev(Index, pev_classname, Classname, charsmax(Classname));         server_print("Classname: %s.", Classname);     } }

Use that, the server should crash not long after you hold refresh.

Edit: I tried it on a listen server and it does crash the game. Nothing else running other than the amxmodx main plugins.

Last edited by PartialCloning; 12-02-2016 at 09:54.
PartialCloning is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode