The date of this post is 2018, and this issue was said that it would be fixed in future versions, right? The same thing had happened to me for a while, I just push the "Mark all read" button, and I no longer get 502 Bad Gateway error.
The bad thing is that there may be users who don't use our forum, because it gives them this error, and they have not told us. Is there no way to force that action for all users?
BTW, my wpForo version is 1.6.5. Thanks!
You also have 2 other options for custom functions.
1. Use a child theme for all modifications you make
or even better
2. Make a plugin of your own with ALL custom functions you use. It just needs a header and the functions. There is plenty of information on how to do that. I use that in my sites and works great.