Skip to content

[Bug] java.lang.IllegalStateException: State is not enabled #25944

Description

@edharvakhitov

Search before reporting

  • I searched in the issues and found nothing similar.

Read release policy

  • I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.

User environment

Broker version (check with bin/pulsar version) - 4.2.1 and 4.0.10
Broker Operating system and hardware type (Windows with wsl or amazon linux)
Broker Java version (17)

Issue Description

What happened?

I ran Pulsar in standalone mode and created a function. When producing a message, it failed with:

What were you trying to do?

Run a stateful Pulsar Function for deduplication.

What did you expect to happen?

The function processes messages and writes output normally.

What actually happened instead?

The function failed at runtime with a state-related exception.

Why do you believe this is a bug?

The function was created successfully with no warnings, but fails at runtime because state is not enabled, which was not clearly indicated or validated during setup. Function runs good if does not use state and with state show error.

Error messages

2026-06-03T13:05:01,169+0000 [pulsar-timer-28-1] INFO  org.apache.pulsar.client.impl.ConsumerStatsRecorderImpl - [persistent://public/default/my-topic] [public/default/dedup-function] [aGzPe] Prefetched messages: 0 --- Consume throughput received: 0.03 msgs/s --- 0.00 Mbit/s --- Ack sent rate: 0.00 ack/s --- Failed messages: 0 --- batch messages: 0 ---Failed acks: 0
2026-06-03T13:05:12,012+0000 [pulsar-timer-28-1] INFO  org.apache.pulsar.client.impl.NegativeAcksTracker - [ConsumerBase{subscription='public/default/dedup-function', consumerName='aGzPe', topic='persistent://public/default/my-topic'}] 2 messages will be re-delivered
2026-06-03T13:05:12,139+0000 [public/default/dedup-function-0] INFO  function-dedup-function - Received message newsId=1
2026-06-03T13:05:12,140+0000 [public/default/dedup-function-0] WARN  org.apache.pulsar.functions.instance.JavaInstanceRunnable - Encountered exception when processing message PulsarRecord(topicName=Optional[persistent://public/default/my-topic], partition=0, message=Optional[org.apache.pulsar.client.impl.MessageImpl@4cc2fdbe], schema=org.apache.pulsar.client.impl.schema.StringSchema@24b25fc7, failFunction=org.apache.pulsar.functions.source.PulsarSource$$Lambda/0x00007f074c4f6680@64d2bc5e, ackFunction=org.apache.pulsar.functions.source.PulsarSource$$Lambda/0x00007f074c4f6468@38ccb3eb, customAckFunction=org.apache.pulsar.functions.source.PulsarSource$$Lambda/0x00007f074c4f6240@359a92a)
java.lang.IllegalStateException: State public/default/dedup-function is not enabled.
	at com.google.common.base.Preconditions.checkState(Preconditions.java:854)
	at org.apache.pulsar.functions.instance.ContextImpl.ensureStateEnabled(ContextImpl.java:396)
	at org.apache.pulsar.functions.instance.ContextImpl.getState(ContextImpl.java:458)
	at com.refinitiv.news.DedupFunction.process(DedupFunction.java:25)
	at com.refinitiv.news.DedupFunction.process(DedupFunction.java:8)
	at org.apache.pulsar.functions.instance.JavaInstance.handleMessage(JavaInstance.java:125)
	at org.apache.pulsar.functions.instance.JavaInstanceRunnable.run(JavaInstanceRunnable.java:342)
	at java.base/java.lang.Thread.run(Thread.java:1583)

Reproducing the issue

Reproducing the issue

Environment

  • Apache Pulsar version: 4.0.10 (binary download)
  • Mode: Standalone
  • OS: WSL (Windows Subsystem for Linux)

Steps to reproduce

  1. Start Pulsar in standalone mode:
bin/pulsar standalone

Create a Pulsar Function:

bin/pulsar-admin functions create \
  --name dedup-function \
  --tenant public \
  --namespace default \
  --jar ~/apache-pulsar-4.0.10-bin/apache-pulsar-4.0.10/functions/function.jar \
  --classname com.refinitiv.news.DedupFunction \
  --inputs persistent://public/default/my-topic \
  --output persistent://public/default/my-output-topic

Produce a test message:


bin/pulsar-client produce \
  persistent://public/default/my-topic \
  -m '{"newsId":"123","title":"hello"}' \
  -p newsId=1

Function code (any that use state):

import org.apache.pulsar.functions.api.Context;
import org.apache.pulsar.functions.api.Function;

import java.nio.ByteBuffer;

public class DedupFunction implements Function<String, String> {

    @Override
    public String process(String input, Context context) throws Exception {

        String newsId = context.getCurrentRecord()
                .getProperties()
                .get("newsId");

        context.getLogger().info("Received message newsId={}", newsId);

        if (newsId == null) {
            context.getLogger().warn("No newsId, forwarding message");
            return input;
        }

        if (context.getState(newsId) != null) {
            context.getLogger().info("Duplicate detected: {}", newsId);
            return null; 
        }

        context.putState(newsId, ByteBuffer.wrap(new byte[]{1}));

        context.getLogger().info("New message stored: {}", newsId);

        return input;
    }
}

Additional information

I had the same issue when tried with docker in standalone mode, or with compose file like in tutorial https://pulsar.apache.org/docs/4.2.x/getting-started-docker-compose/

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugThe PR fixed a bug or issue reported a bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions