Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE when getting native thread id #15301

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.logstash.config.ir.compiler.AbstractOutputDelegatorExt;

import java.util.Collection;
import java.util.Optional;

/**
* JRuby extension
Expand Down Expand Up @@ -161,7 +162,7 @@ private RubyArray workerStates(final ThreadContext context, final RubyHash batch
final RubyArray result = context.runtime.newArray();
((Iterable<IRubyObject>) pipeline.callMethod(context, "worker_threads"))
.forEach(thread -> {
final long nativeThreadId = ((RubyThread) thread).getNativeThread().getId();

final RubyHash hash = RubyHash.newHash(context.runtime);
IRubyObject status = thread.callMethod(context, "status");
if (status.isNil()) {
Expand All @@ -170,8 +171,15 @@ private RubyArray workerStates(final ThreadContext context, final RubyHash batch
hash.op_aset(context, STATUS_KEY, status);
hash.op_aset(context, ALIVE_KEY, thread.callMethod(context, "alive?"));
hash.op_aset(context, INDEX_KEY, context.runtime.newFixnum(result.size()));
final IRubyObject batch = batchMap.op_aref(context, context.runtime.newFixnum(nativeThreadId));
hash.op_aset(context, INFLIGHT_COUNT_KEY, extractBatchSize(context, batch));

IRubyObject batchSize = Optional.of((RubyThread) thread)
.map(RubyThread::getNativeThread)
.map(Thread::getId)
.map(id -> batchMap.op_aref(context, context.runtime.newFixnum(id)))
.map(batch -> extractBatchSize(context, batch))
.orElse(context.runtime.newFixnum(0L));

hash.op_aset(context, INFLIGHT_COUNT_KEY, batchSize);
result.add(hash);
});
return result;
Expand Down