From 403150300ed55ab18407acf4b39008f281ad23d4 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 19 Jan 2019 20:23:26 -0600 Subject: [PATCH] hopefully fully fixed FDs now --- onionr/api.py | 25 +++++++++++++++++++------ onionr/communicator2.py | 2 +- onionr/onionrdaemontools.py | 2 +- onionr/static-data/default_config.json | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/onionr/api.py b/onionr/api.py index e24e21a6..88f5f69f 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -17,9 +17,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -from gevent.pywsgi import WSGIServer -import gevent.monkey -gevent.monkey.patch_socket() +from gevent.pywsgi import WSGIServer, WSGIHandler +from gevent import Timeout +#import gevent.monkey +#gevent.monkey.patch_socket() import flask, cgi from flask import request, Response, abort, send_from_directory import sys, random, threading, hmac, hashlib, base64, time, math, os, json, socket @@ -27,6 +28,17 @@ import core from onionrblockapi import Block import onionrutils, onionrexceptions, onionrcrypto, blockimporter, onionrevents as events, logger, config, onionr +class FDSafeHandler(WSGIHandler): + def handle(self): + timeout = Timeout(10, exception=Exception) + timeout.start() + + #timeout = gevent.Timeout.start_new(3) + try: + WSGIHandler.handle(self) + except Timeout as ex: + raise + def guessMime(path): ''' Guesses the mime type of a file from the input filename @@ -221,7 +233,7 @@ class PublicAPI: clientAPI._core.refreshFirstStartVars() self.torAdder = clientAPI._core.hsAddress time.sleep(1) - self.httpServer = WSGIServer((self.host, self.bindPort), app, log=None) + self.httpServer = WSGIServer((self.host, self.bindPort), app, log=None, handler_class=FDSafeHandler) self.httpServer.serve_forever() class API: @@ -394,13 +406,14 @@ class API: @app.route('/getstats') def getStats(): - return Response(self._core.serializer.getStats()) + return Response("disabled") + #return Response(self._core.serializer.getStats()) @app.route('/getuptime') def showUptime(): return Response(str(self.getUptime())) - self.httpServer = WSGIServer((self.host, bindPort), app, log=None) + self.httpServer = WSGIServer((self.host, bindPort), app, log=None, handler_class=FDSafeHandler) self.httpServer.serve_forever() def setPublicAPIInstance(self, inst): diff --git a/onionr/communicator2.py b/onionr/communicator2.py index e258c8c8..de55a4fc 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -97,7 +97,7 @@ class OnionrCommunicatorDaemon: # Set timers, function reference, seconds # requiresPeer True means the timer function won't fire if we have no connected peers peerPoolTimer = OnionrCommunicatorTimers(self, self.getOnlinePeers, 60, maxThreads=1) - OnionrCommunicatorTimers(self, self.runCheck, 1) + OnionrCommunicatorTimers(self, self.runCheck, 2, maxThreads=1) OnionrCommunicatorTimers(self, self.lookupBlocks, self._core.config.get('timers.lookupBlocks'), requiresPeer=True, maxThreads=1) OnionrCommunicatorTimers(self, self.getBlocks, self._core.config.get('timers.getBlocks'), requiresPeer=True, maxThreads=2) OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58) diff --git a/onionr/onionrdaemontools.py b/onionr/onionrdaemontools.py index 9f1ab2a2..38db5d5b 100644 --- a/onionr/onionrdaemontools.py +++ b/onionr/onionrdaemontools.py @@ -74,7 +74,7 @@ class DaemonTools: retData = True self.daemon._core.setAddressInfo(peer, 'introduced', 1) self.daemon._core.setAddressInfo(peer, 'powValue', data['random']) - self.daemon.decrementThreadCount('announceNode') + self.daemon.decrementThreadCount('announceNode') return retData def netCheck(self): diff --git a/onionr/static-data/default_config.json b/onionr/static-data/default_config.json index 93f3a49a..cb7b37b1 100644 --- a/onionr/static-data/default_config.json +++ b/onionr/static-data/default_config.json @@ -50,7 +50,7 @@ "file": { "output": true, - "path": "data/output.log" + "path": "output.log" }, "console" : {