droxit / roxcomposer

This is the droxit microservice framework repository.
GNU Lesser General Public License v3.0
5 stars 0 forks source link

Server Crash when posting to false ElasticSearch Url and logging answer #90

Closed droxit-becker closed 5 years ago

droxit-becker commented 5 years ago

Using the Elasticstore service with a faulty ElasticSearch url (and then logging the requests answer) will cause the server to crash with the following exceptions.

File "/home/janabecker/.local/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw) File "/home/janabecker/.local/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection raise err File "/home/janabecker/.local/lib/python3.6/site-packages/urllib3/util/connection.py", line 70, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/janabecker/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/home/janabecker/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request conn.request(method, url, **httplib_request_kw) File "/usr/lib/python3.6/http/client.py", line 1239, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/lib/python3.6/http/client.py", line 1026, in _send_output self.send(msg) File "/usr/lib/python3.6/http/client.py", line 964, in send self.connect() File "/home/janabecker/.local/lib/python3.6/site-packages/urllib3/connection.py", line 181, in connect conn = self._new_conn() File "/home/janabecker/.local/lib/python3.6/site-packages/urllib3/connection.py", line 168, in _new_conn self, "Failed to establish a new connection: %s" % e) urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f265616ec18>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/janabecker/.local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send timeout=timeout File "/home/janabecker/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen _stacktrace=sys.exc_info()[2]) File "/home/janabecker/.local/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=9200): Max retries exceeded with url: /test/_doc (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f265616ec18>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/janabecker/.local/lib/python3.6/site-packages/roxcomposer/base_service.py", line 224, in listen_to self.on_message(self.roxcomposer_message.payload, self.roxcomposer_message.id) File "/home/janabecker/PycharmProjects/jotb-services/elasticstore/elasticstore.py", line 98, in on_message self.send_es_request(json_doc) File "/home/janabecker/PycharmProjects/jotb-services/elasticstore/elasticstore.py", line 113, in send_es_request r = requests.post(self.es_url + "/" + self.index + "/_doc", data=json_doc, headers=header) File "/home/janabecker/.local/lib/python3.6/site-packages/requests/api.py", line 116, in post return request('post', url, data=data, json=json, kwargs) File "/home/janabecker/.local/lib/python3.6/site-packages/requests/api.py", line 60, in request return session.request(method=method, url=url, kwargs) File "/home/janabecker/.local/lib/python3.6/site-packages/requests/sessions.py", line 524, in request resp = self.send(prep, send_kwargs) File "/home/janabecker/.local/lib/python3.6/site-packages/requests/sessions.py", line 637, in send r = adapter.send(request, kwargs) File "/home/janabecker/.local/lib/python3.6/site-packages/requests/adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=9200): Max retries exceeded with url: /test/_doc (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f265616ec18>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/janabecker/PycharmProjects/jotb-services/elasticstore/elasticstore.py", line 122, in service = ElasticStore(kwargs) File "/home/janabecker/PycharmProjects/jotb-services/elasticstore/elasticstore.py", line 57, in init self.listen() File "/home/janabecker/.local/lib/python3.6/site-packages/roxcomposer/base_service.py", line 236, in listen self.listen_to(self.params['ip'], self.params['port']) File "/home/janabecker/.local/lib/python3.6/site-packages/roxcomposer/base_service.py", line 230, in listen_to self.logger.critical(e.strerror + ' - ' + str(e.traceback)) TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

0xRand0m commented 5 years ago

This is probably due to the str(e.traceback) statement which probably returns None. Python has a class/function to format stack traces. Do the following: confirm the problem by writing a minimal test case in a separete file: Provoke an exception and execute print(str(e.traceback)). If this is None replace the statement using the respective Python utitlities.

0xRand0m commented 5 years ago

Fixed by #99