Author Topic: Return of 502- Bad gateway Error  (Read 57999 times)

0 Members and 1 Guest are viewing this topic.

Offline pknoe3lh

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
  • Trust me I'm an engineer
    • My Homepage
Re: Return of 502- Bad gateway Error
« Reply #175 on: July 25, 2017, 08:59:58 pm »
http://rsgiveaway.knoebel.at

I don't know where the graph's server is, but the 502s that I saw matched with the stars/dots exactly.
From the posts, I think everyone is seeing the same thing from every location.

Germany ;-)

Offline tautech

  • Super Contributor
  • ***
  • Posts: 28371
  • Country: nz
  • Taupaki Technologies Ltd. Siglent Distributor NZ.
    • Taupaki Technologies Ltd.
Re: Return of 502- Bad gateway Error
« Reply #176 on: July 25, 2017, 09:04:31 pm »
Too many Aussies are currently online. Probably the server can't handle it.  :rant:  ;)
Nah, they're just waking up. It's around 7am there.
Avid Rabid Hobbyist
Siglent Youtube channel: https://www.youtube.com/@SiglentVideo/videos
 

Offline RGB255_0_0

  • Frequent Contributor
  • **
  • Posts: 772
  • Country: gb
Re: Return of 502- Bad gateway Error
« Reply #177 on: July 25, 2017, 09:05:29 pm »
Should set the server to reboot every 3 days as a work around until this gets sorted. It did seem to work in the short term.
Your toaster just set fire to an African child over TCP.
 

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: Return of 502- Bad gateway Error
« Reply #178 on: July 25, 2017, 09:18:50 pm »
Should set the server to reboot every 3 days

3 times a day would be better.  :)
I was here when dave rebooted, it was very quick, I only saw one 521.
.  That took much longer than I thought it would.
 

Offline Naguissa

  • Regular Contributor
  • *
  • Posts: 114
  • Country: es
    • Foro de electricidad, electrónica y DIY / HUM en español
Re: Return of 502- Bad gateway Error
« Reply #179 on: July 25, 2017, 09:32:49 pm »
Dave, you can try to intall:
memcache and php-memcache or php5-memcache

And, of php5, php5-apc or php5-apcu

https://www.simplemachines.org/community/index.php?topic=467415.0

Enviado desde mi Jolla mediante Tapatalk


Offline tablatronix

  • Regular Contributor
  • *
  • Posts: 199
  • Country: us
Re: Return of 502- Bad gateway Error
« Reply #180 on: July 25, 2017, 09:40:55 pm »
If this site uses cloudflare you might need to make sure your forum has X-Forwarded-For inspection enabled.
 

Offline Conrad Hoffman

  • Super Contributor
  • ***
  • Posts: 1930
  • Country: us
    • The Messy Basement
Re: Return of 502- Bad gateway Error
« Reply #181 on: July 25, 2017, 10:32:26 pm »
In the US here. Sometimes the 502s drive me crazy from home (DSL), yet it seems to happen less often at work. (yes, I check in on breaks and lunch) Might just be the time of day. Sometimes I'll do a flush on cached Chrome data and then no 502s. Or maybe it's just luck. There doesn't seem to be a pattern to it. Frustrating.
 

Offline gnif

  • Administrator
  • *****
  • Posts: 1676
  • Country: au
Re: Return of 502- Bad gateway Error
« Reply #182 on: July 25, 2017, 10:36:08 pm »
Hi Everyone,

I am sorry about the lack of attention I have given this forum as of late, I have had little free time to assist here. That said I am digging into this now and will hopefully have a solution soon.

If this site uses cloudflare you might need to make sure your forum has X-Forwarded-For inspection enabled.

Thanks for the info, this is already catered for though. 502 is a server side error, a failure of Nginx to communicate with the PHP fpm process.
 
The following users thanked this post: tautech, Gary350z, MK14

Offline Mr.B

  • Supporter
  • ****
  • Posts: 1237
  • Country: nz
Re: Return of 502- Bad gateway Error
« Reply #183 on: July 25, 2017, 10:36:19 pm »
I approach the thinking of all of my posts using AI in the first instance. (Awkward Irregularity)
 

Offline tautech

  • Super Contributor
  • ***
  • Posts: 28371
  • Country: nz
  • Taupaki Technologies Ltd. Siglent Distributor NZ.
    • Taupaki Technologies Ltd.
Re: Return of 502- Bad gateway Error
« Reply #184 on: July 25, 2017, 10:47:04 pm »
Hi Everyone,

I am sorry about the lack of attention I have given this forum as of late, I have had little free time to assist here. That said I am digging into this now and will hopefully have a solution soon.
Be sure to check this site put together by pknoe3lh:
http://rsgiveaway.knoebel.at/

You might get some clues from correlation of error reports on the server to it.
Avid Rabid Hobbyist
Siglent Youtube channel: https://www.youtube.com/@SiglentVideo/videos
 
The following users thanked this post: MK14

Offline WastelandTek

  • Frequent Contributor
  • **
  • Posts: 609
  • Country: 00
Re: Return of 502- Bad gateway Error
« Reply #185 on: July 25, 2017, 11:04:50 pm »
Thanks for checking in gnif

it has been pretty bad
I'm new here, but I tend to be pretty gregarious, so if I'm out of my lane please call me out.
 

Offline gnif

  • Administrator
  • *****
  • Posts: 1676
  • Country: au
Re: Return of 502- Bad gateway Error
« Reply #186 on: July 25, 2017, 11:08:19 pm »
Dave, you can try to intall:
memcache and php-memcache or php5-memcache

And, of php5, php5-apc or php5-apcu

https://www.simplemachines.org/community/index.php?topic=467415.0

Enviado desde mi Jolla mediante Tapatalk

Thanks but we are already leveraging opcode caching and memcached.

Hi Everyone,

I am sorry about the lack of attention I have given this forum as of late, I have had little free time to assist here. That said I am digging into this now and will hopefully have a solution soon.
Be sure to check this site put together by pknoe3lh:
http://rsgiveaway.knoebel.at/

You might get some clues from correlation of error reports on the server to it.

I appreciate the information but I am already collecting this data amongst much more, this server is fully monitored but as I stated, due to the fact that I offer this to Dave as a favor I can not justify the time on it when I have paying clients that demand attention.

Thanks for checking in gnif

it has been pretty bad

You're most welcome :)
 
The following users thanked this post: tautech, MK14

Offline gnif

  • Administrator
  • *****
  • Posts: 1676
  • Country: au
Re: Return of 502- Bad gateway Error
« Reply #187 on: July 25, 2017, 11:12:04 pm »
Just a heads up, I will be restarting services on the server to tune/test and debug, this will cause disruptions to the site. Reports of outages during this time only serve to distract, I will update here when things are stable and no further changes are expected.
 
The following users thanked this post: dr.diesel, Muttley Snickers, gnavigator1007, MK14, The Soulman

Offline gnif

  • Administrator
  • *****
  • Posts: 1676
  • Country: au
Re: Return of 502- Bad gateway Error
« Reply #188 on: July 26, 2017, 12:35:34 am »
I believe I have located the issue, it is a bug with how PHP handles file locking of the sessions. I attached a debugger to PHP during antoher outage just now which confirmed it was hung on a file lock request.

Code: [Select]
(gdb) bt
#0  0x00007f7b27384c47 in flock () from /lib64/libc.so.6
#1  0x0000000000667795 in ps_files_open (data=0x7f7b264bb0c0, key=0x7f7b264ad018 "hb2g026hbbs97ukagljo5ainok") at *REDACTED*/ext/session/mod_files.c:214
#2  0x0000000000667a88 in ps_read_files (mod_data=<value optimized out>, key=<value optimized out>, val=0x7fff595009a8, maxlifetime=<value optimized out>)
    at *REDACTED*/ext/session/mod_files.c:482
#3  0x0000000000664c07 in php_session_initialize () at *REDACTED*/ext/session/session.c:426
#4  0x000000000066518d in php_session_start () at *REDACTED*/ext/session/session.c:1534

To work around this I am evaluating switching session storage to memcached, it seems though that SMF doesn't like this much, I am investigating options right now to try to resolve this.

Update: SMF is trying to store too much data in sessions to use memcached, I have instead switched it over to session storage in the database. We turned this off years ago due to the performance hit due to the inability to use InnoDB tables, and a lack of server RAM. This is no longer the case, and as such we can return to using the native SMF database session storage.
« Last Edit: July 26, 2017, 12:55:36 am by gnif »
 
The following users thanked this post: EEVblog, pknoe3lh

Offline Muttley Snickers

  • Supporter
  • ****
  • Posts: 2341
  • Country: au
  • Cursed: 679 times
Re: Return of 502- Bad gateway Error
« Reply #189 on: July 26, 2017, 01:17:08 am »
This is probably just a side effect of your process gnif and I don't mean to distract you but the numbers of online users dropped off dramatically during the last hour or so. Oh here we go, the third picture is the most recent and shows the users returning, somebody must have left the gate open.   :palm:
 

Offline gnif

  • Administrator
  • *****
  • Posts: 1676
  • Country: au
Re: Return of 502- Bad gateway Error
« Reply #190 on: July 26, 2017, 01:19:38 am »
This is probably just a side effect of your process gnif and I don't mean to distract you but the numbers of online users dropped off dramatically during the last hour or so. Oh here we go, the third picture is the most recent and shows the users returning, somebody must have left the gate open.   :palm:

The switch of the session storage will have logged everyone out and messed with the stats of online users.
 

Offline hendorog

  • Super Contributor
  • ***
  • Posts: 1617
  • Country: nz
Re: Return of 502- Bad gateway Error
« Reply #191 on: July 26, 2017, 01:21:27 am »
Quick lock the buggers out before they sneak back in, it's going nicely again now  :phew:
 
The following users thanked this post: tautech

Offline richnormand

  • Supporter
  • ****
  • Posts: 682
  • Country: ca
Re: Return of 502- Bad gateway Error
« Reply #192 on: July 26, 2017, 02:31:15 am »
Today is pretty bad. Combination of gateway errors and very very slow response if it works..... :(

OK just came back after dinner and it did show gateway error again on my Chrome browser, just like this afternoon. Cleared up the cookies and cache and all is OK now (till next time).

Although the original issue is server side my browser will keep giving me the original cached error page, even though the real problem has now been cleared it seem.
Lots of people might "see" the error a much longer time than it was active if they don't cleanup the caches. The behaviour might be different with different browsers of course.


« Last Edit: July 26, 2017, 02:35:23 am by richnormand »
Repair, Renew, Reuse, Recycle, Rebuild, Reduce, Recover, Repurpose, Restore, Refurbish, Recondition, Renovate
 

Offline pknoe3lh

  • Regular Contributor
  • *
  • Posts: 115
  • Country: at
  • Trust me I'm an engineer
    • My Homepage
Re: Return of 502- Bad gateway Error
« Reply #193 on: July 26, 2017, 08:12:47 am »
Looks good again  :-+

http://rsgiveaway.knoebel.at

Offline gnif

  • Administrator
  • *****
  • Posts: 1676
  • Country: au
Re: Return of 502- Bad gateway Error
« Reply #194 on: July 26, 2017, 10:38:30 am »
Today is pretty bad. Combination of gateway errors and very very slow response if it works..... :(

OK just came back after dinner and it did show gateway error again on my Chrome browser, just like this afternoon. Cleared up the cookies and cache and all is OK now (till next time).

Although the original issue is server side my browser will keep giving me the original cached error page, even though the real problem has now been cleared it seem.
Lots of people might "see" the error a much longer time than it was active if they don't cleanup the caches. The behaviour might be different with different browsers of course.

This could be CloudFlare and your browser, it will cache the 502s to try to alleviate some load from the target server. The server logs show that there has been no 502's since I corrected the session issue, but with this kind of error only time will tell if it is finally fixed. Thank you everyone for being so patient, I take it personally when things I support do not function correctly as it is a reflection of my technical ability.
 
The following users thanked this post: MK14, richnormand

Offline RGB255_0_0

  • Frequent Contributor
  • **
  • Posts: 772
  • Country: gb
Re: Return of 502- Bad gateway Error
« Reply #195 on: July 26, 2017, 02:19:46 pm »
Today is pretty bad. Combination of gateway errors and very very slow response if it works..... :(

OK just came back after dinner and it did show gateway error again on my Chrome browser, just like this afternoon. Cleared up the cookies and cache and all is OK now (till next time).

Although the original issue is server side my browser will keep giving me the original cached error page, even though the real problem has now been cleared it seem.
Lots of people might "see" the error a much longer time than it was active if they don't cleanup the caches. The behaviour might be different with different browsers of course.

This could be CloudFlare and your browser, it will cache the 502s to try to alleviate some load from the target server. The server logs show that there has been no 502's since I corrected the session issue, but with this kind of error only time will tell if it is finally fixed. Thank you everyone for being so patient, I take it personally when things I support do not function correctly as it is a reflection of my technical ability.
It shouldn't question your ability but it does question your ability to provide time  ;)

I think I speak for everyone when I say we appreciate your effort.
Your toaster just set fire to an African child over TCP.
 

Offline gnif

  • Administrator
  • *****
  • Posts: 1676
  • Country: au
Re: Return of 502- Bad gateway Error
« Reply #196 on: July 26, 2017, 03:16:30 pm »
I believe I have located the issue, it is a bug with how PHP handles file locking of the sessions. I attached a debugger to PHP during antoher outage just now which confirmed it was hung on a file lock request.


To work around this I am evaluating switching session storage to memcached, it seems though that SMF doesn't like this much, I am investigating options right now to try to resolve this.

Update: SMF is trying to store too much data in sessions to use memcached, I have instead switched it over to session storage in the database. We turned this off years ago due to the performance hit due to the inability to use InnoDB tables, and a lack of server RAM. This is no longer the case, and as such we can return to using the native SMF database session storage.

Does SMF follow the same session locking strategy whether memcached is used or a table? One being faster than the other only. If that is the case (I don't claim to know one way or the other) then won't the session lock still happen under the same circumstances albeit perhaps with a smaller timing window in the faster case?

At the moment just based on reading what you've said I don't see that waiting on an unavailable lock is a bug necessarily. Waiting may not be the best response in some cases, and it might be better for a session to release all locks and try later if some locks are currently held.

Perhaps if gnif hasn't the time explain the nature of the bug someone else here who does this stuff can explain it.

PHP can handle sessions using several different methods.

1) Files (default). It creates a /tmp/sess_XXXXX file for each session which contains the PHP serialized data for the session.
2) Memcache, in this instance memcache handles the atomic operations in RAM rather then on the FS, which is extremely fast, but... the record size is constrained too much for SMF to work with it.
3) Custom, you can register your own handlers and store it however you want, in the case of SMF it is using a session table in the database.

With files, PHP relies on the flock system call, and then funlock at the end of the request, this is fine normally, but when you start to get a very busy website if a PHP process takes an age to complete and gets terminated by the CGI handler (FPM in this instance), the call to funlock never gets called, the file remains locked (PHP processes are reused, the process doesn't terminate so the kernel doesn't clean these up). Then on the next request, PHP hangs without a timeout waiting on it's call to flock the session. This should really be handled better, such as registering the locks with the CGI handler, or something similar. There is only a finite amount of PHP handlers running, once they are all hung up on waiting for locks that will never occur, there are none left for Nginx to pass the request to and thus the 502.

With memcache, there is a limit on the object size stored, SMF is storing way too much in the session to store it in memcache. Also there is the issue of persistance, memcache is not guaranteed not to evict the data stored to make room for other stuff, there is a chance that your cached data gets dropped.

With the custom method, in this instance DB storage, it is up to MySQL to handle the locking, which detects if the session is terminated and unlocks any locks held when the client disconnects.

I hope this clears things up a little.
« Last Edit: July 26, 2017, 03:19:55 pm by gnif »
 
The following users thanked this post: alm

Offline gnif

  • Administrator
  • *****
  • Posts: 1676
  • Country: au
Re: Return of 502- Bad gateway Error
« Reply #197 on: July 27, 2017, 01:34:11 am »
It sounds like this is an inherent design problem in PHP and short of a change it is a vulnerability the system admin can't get rid of. Not without some means to clear hung sessions holding critical locks.

It must be a common probem in busy servers using the same architecture then. If so I am surprised someone else hasn't already developed a custom solution that can be installed. Or have they?

This is the first instance I personally have seen of this issue on a production system, usually however when a site grows as large as this one you ditch things like cPanel and run full dedicated, which gives much greater control on how the server operates. Unfortunately Dave needs the ability to manage this server when I am not around so this is not really much of an option for him.

What happens if a forum user logs out? Does that trigger a release of the lock held for that session? Is that why you disconnected people yesterday?

It really depends on the application, most apps will call session_destroy which does exactly that, removes the entire session record/file/cache entry, others will blank the auth data in the session. Even if you are not logged in though you have a session, every visitor is assigned one so the website can track you even if you are a guest. This is common practice.

As for the 'disconnection' of people, no, this was not intentional, it is a side effect of changing storage methods. We went from files on disk to database records, there is no means to import the sessions from the files on disk into the database.
 

Offline PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5127
  • Country: nl
Re: Return of 502- Bad gateway Error
« Reply #198 on: July 27, 2017, 07:37:15 am »
And... it's back  >:(   :horse:
Keyboard error: Press F1 to continue.
 

Offline nugglix

  • Regular Contributor
  • *
  • Posts: 209
  • Country: de
Re: Return of 502- Bad gateway Error
« Reply #199 on: July 27, 2017, 07:37:39 am »
It's back.  :--

Corresponds  to the load times shown at http://rsgiveaway.knoebel.at/
This really starts to suck!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf