Hi everyone, I am a software developer who has never worked in Ruby before. I am building an application using Logstash, and Logstash permits Ruby scripting. (I’m sorry, I don’t know what version of Ruby, but I assume a recent version.) At one point in my Logstash, I am using the following Ruby code:
socket = TCPSocket.new("192.168.3.1", 12345)
socket.write event.to_hash
response = socket.recv(10000000)
event.set("NewData", response)
In Logstash, an event is a data record, which you can think of as a record in a database. So, the above code should do the following:
- Opens a TCP socket to remote host 192.168.3.1, port 12345
- Writes the event (expressed as a hash string) to the socket
- …the remote server does some processing…
- When the remote server sends a response back, the Ruby code writes that response is written to variable “response”
- Adds a new field to the event called “NewData,” and populates it with the value of the “response” variable.
Should be simple. But I’ve noticed that perhaps 33% of the time, I don’t see a valid value in the “NewData” field. And when I look at Logstash’s log, I see this:
[2020-10-09T16:34:10,476][ERROR][logstash.filters.ruby ][main][09de6b10cf3fdaa7a5ae8b4e3fcd73837267db580130edc34de5fc2c7e5e9cb2] Ruby exception occurred: Java heap space
I see that line hundreds of times in my log. I don’t know what it means, but that “Ruby exception occurred” makes me wonder if one of the four lines of Ruby code is throwing an exception, and hence, is my problem.
If any of those lines is throwing an exception, I’m betting it’s the recv()
line? Or maybe the write()
line? I just don’t know, and Googling these functions hasn’t really helped much. Can anyone offer any practical experience here? What, if anything, might be throwing these exceptions? I realize this is an open-ended question; thanks for any advice you might be able to offer.