Skip to content

[yugabyte/yugabyte-db#30391] Handle NPE in isBeforeImageEnabled when using Logical Replication#402

Open
bakul-gupta wants to merge 2 commits intomainfrom
grpc-logical-replication-support
Open

[yugabyte/yugabyte-db#30391] Handle NPE in isBeforeImageEnabled when using Logical Replication#402
bakul-gupta wants to merge 2 commits intomainfrom
grpc-logical-replication-support

Conversation

@bakul-gupta
Copy link
Collaborator

Jira Link: DB-20273

Description

While validating gRPC connector support for Logical Replication (using a replication slot + publication instead of a stream created via yb-admin), the connector crashes during initialization with a NullPointerException in YBClientUtils.isBeforeImageEnabled().

Error while trying to get before image status
java.lang.NullPointerException
  at io.debezium.connector.yugabytedb.YBClientUtils.isBeforeImageEnabled(YBClientUtils.java:347)
  at io.debezium.connector.yugabytedb.YugabyteDBgRPCConnector.taskConfigs(YugabyteDBgRPCConnector.java:167)

Solution

When using a replication slot + publication instead of a yb-admin stream, the CDC stream options may not contain a record_type key, causing cdcStreamInfo.getOptions().get("record_type") to return null and the subsequent .equals() call to throw an NPE. Added a null check in YBClientUtils.isBeforeImageEnabled() — if record_type is missing, log a warning and return false (before image disabled).

@bakul-gupta bakul-gupta marked this pull request as ready for review March 12, 2026 07:17
@Sumukh-Phalgaonkar
Copy link
Collaborator

Can you add a UT which would fail without your fix and validate that the fix works

|| cdcStreamInfo.getOptions().get("record_type").equals(CDCRecordType.MODIFIED_COLUMNS_OLD_AND_NEW_IMAGES.name()))
|| (cdcStreamInfo.getOptions().get("record_type").equals(CDCRecordType.PG_FULL.name())
|| cdcStreamInfo.getOptions().get("record_type").equals(CDCRecordType.PG_CHANGE_OLD_NEW.name()));
String recordType = cdcStreamInfo.getOptions().get("record_type");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when the user wants before image with a gRPC stream that has replication slot assiociated with it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the before image to true fixes the case you are talking about. And when the table has a replica identity say default then the before image is sent as null even though the flag is true as the message received does not have a before image.

@bakul-gupta bakul-gupta force-pushed the grpc-logical-replication-support branch from b7c8279 to f1bf36c Compare March 23, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants