Fix a thread leak in `SamplingService` when updated sampling policy in the runtime. (#487)

This commit is contained in:
hyhyf 2023-03-27 22:15:10 +08:00 committed by GitHub
parent e91514c634
commit c0b4447540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -22,6 +22,7 @@ Release Notes.
* Fix thrift plugin generate duplicate traceid when `sendBase` error occurs
* Support keep trace profiling when cross-thread.
* Fix unexpected whitespace of the command catalogs in several Redis plugins.
* Fix a thread leak in `SamplingService` when updated sampling policy in the runtime.
#### Documentation
* Update docs of Tracing APIs, reorganize the API docs into six parts.

View File

@ -51,6 +51,7 @@ public class SamplingService implements BootService {
private volatile ScheduledFuture<?> scheduledFuture;
private SamplingRateWatcher samplingRateWatcher;
private ScheduledExecutorService service;
@Override
public void prepare() {
@ -58,6 +59,8 @@ public class SamplingService implements BootService {
@Override
public void boot() {
service = Executors.newSingleThreadScheduledExecutor(
new DefaultNamedThreadFactory("SamplingService"));
samplingRateWatcher = new SamplingRateWatcher("agent.sample_n_per_3_secs", this);
ServiceManager.INSTANCE.findService(ConfigurationDiscoveryService.class)
.registerAgentConfigChangeWatcher(samplingRateWatcher);
@ -118,8 +121,6 @@ public class SamplingService implements BootService {
if (!on) {
on = true;
this.resetSamplingFactor();
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(
new DefaultNamedThreadFactory("SamplingService"));
scheduledFuture = service.scheduleAtFixedRate(new RunnableWithExceptionProtection(
this::resetSamplingFactor, t -> LOGGER.error("unexpected exception.", t)), 0, 3, TimeUnit.SECONDS);
LOGGER.debug(