ResourceWarning: unclosed <socket.socket... #1018
-
I using elastalert2 on docker, I have created rules with the website's login test (the website has many login turns). I used Enhancements to check some conditions and use Dropmatchexception() to remove most of them. Then I received a warning ...
Is Dropmatchexception() in Enhancements did not close socket when match rule (Terminate in Enhancements Class) or large amount of alert makes Elastalert unable to handle the requests? i see discussions/887 but not helpful. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If you are opening connections in your enhancement class then yes you are responsible for ensuring they are properly closed. However, I suspect what you're observing is an artifact of Python's garbage collection combined with urllib3's connection pooling. Another user posted something similar earlier this year: #887 And elastic discussions on this topic also exist: elastic/elasticsearch-py#1533 This AWS issue has some useful background, even though it's specific to boto3, but the premise is similar: boto/boto3#454 Based on the public information like that in the links above, it appears that this warning may not be cause for concern. If you experiencing connection errors or crashing I would be interested in seeing a reproducible test case to look into it. If you're not experiencing any problems, you can consider filtering out the warnings, as is described in several discussions like the ones above. |
Beta Was this translation helpful? Give feedback.
-
Thank for your reply. class CheckUserLogin(BaseEnhancement):
def process(self, match):
# add field if username == "admin" && uri == "/api/user/admin/x" else drop
if match['username'] == "admin" && match['uri'] == "/api/user/admin/x":
match["severity"] = "warning"
else:
# Do I need Close Socket here? how do it?
raise DropMatchException() |
Beta Was this translation helpful? Give feedback.
If you are opening connections in your enhancement class then yes you are responsible for ensuring they are properly closed. However, I suspect what you're observing is an artifact of Python's garbage collection combined with urllib3's connection pooling.
Another user posted something similar earlier this year: #887
And elastic discussions on this topic also exist: elastic/elasticsearch-py#1533
This AWS issue has some useful background, even though it's specific to boto3, but the premise is similar: boto/boto3#454
Based on the public information like that in the links above, it appears that this warning may not be cause for concern. If you experiencing connection errors or crashing I woul…