Fixes memory leak, saltclients should be cleaned after used.

This commit is contained in:
gwiyeong 2018-02-19 11:07:36 +09:00 committed by kstreee
parent aba00805f4
commit 48080a1bae
No known key found for this signature in database
GPG Key ID: 43F5F108E2B7859E

View File

@ -236,28 +236,6 @@ logger = logging.getLogger()
# - "wheel" (need async api...) # - "wheel" (need async api...)
class SaltClientsMixIn(object):
'''
MixIn class to container all of the salt clients that the API needs
'''
# TODO: load this proactively, instead of waiting for a request
__saltclients = None
@property
def saltclients(self):
if SaltClientsMixIn.__saltclients is None:
local_client = salt.client.get_local_client(mopts=self.application.opts)
# TODO: refreshing clients using cachedict
SaltClientsMixIn.__saltclients = {
'local': local_client.run_job_async,
# not the actual client we'll use.. but its what we'll use to get args
'local_async': local_client.run_job_async,
'runner': salt.runner.RunnerClient(opts=self.application.opts).cmd_async,
'runner_async': None, # empty, since we use the same client as `runner`
}
return SaltClientsMixIn.__saltclients
AUTH_TOKEN_HEADER = 'X-Auth-Token' AUTH_TOKEN_HEADER = 'X-Auth-Token'
AUTH_COOKIE_NAME = 'session_id' AUTH_COOKIE_NAME = 'session_id'
@ -388,7 +366,7 @@ class EventListener(object):
del self.timeout_map[future] del self.timeout_map[future]
class BaseSaltAPIHandler(tornado.web.RequestHandler, SaltClientsMixIn): # pylint: disable=W0223 class BaseSaltAPIHandler(tornado.web.RequestHandler): # pylint: disable=W0223
ct_out_map = ( ct_out_map = (
('application/json', json.dumps), ('application/json', json.dumps),
('application/x-yaml', yaml.safe_dump), ('application/x-yaml', yaml.safe_dump),
@ -416,6 +394,16 @@ class BaseSaltAPIHandler(tornado.web.RequestHandler, SaltClientsMixIn): # pylin
self.application.opts, self.application.opts,
) )
if not hasattr(self, 'saltclients'):
local_client = salt.client.get_local_client(mopts=self.application.opts)
self.saltclients = {
'local': local_client.run_job_async,
# not the actual client we'll use.. but its what we'll use to get args
'local_async': local_client.run_job_async,
'runner': salt.runner.RunnerClient(opts=self.application.opts).cmd_async,
'runner_async': None, # empty, since we use the same client as `runner`
}
@property @property
def token(self): def token(self):
''' '''
@ -745,7 +733,7 @@ class SaltAuthHandler(BaseSaltAPIHandler): # pylint: disable=W0223
self.write(self.serialize(ret)) self.write(self.serialize(ret))
class SaltAPIHandler(BaseSaltAPIHandler, SaltClientsMixIn): # pylint: disable=W0223 class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
''' '''
Main API handler for base "/" Main API handler for base "/"
''' '''