Skip to content

Commit a7162c8

Browse files
mohityadav766claude
andcommitted
fix: guard search indexing failure recording against invalid entity IDs
Skip failure records when entity IDs are null or exceed the 36-char column limit, extract IDs from EntityInterface instances in PartitionWorker, and swallow ClosedChannelException noise in the Jetty12 WebSocket handler. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0379cd1 commit a7162c8

3 files changed

Lines changed: 41 additions & 4 deletions

File tree

openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/searchIndex/IndexingFailureRecorder.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum FailureStage {
1919
}
2020

2121
private static final int DEFAULT_BATCH_SIZE = 100;
22+
private static final int ENTITY_ID_MAX_LENGTH = 36;
2223

2324
private final CollectionDAO.SearchIndexFailureDAO failureDAO;
2425
private final String jobId;
@@ -115,6 +116,16 @@ private void recordFailure(
115116
return;
116117
}
117118

119+
if (entityId != null && entityId.length() > ENTITY_ID_MAX_LENGTH) {
120+
LOG.warn(
121+
"Skipping failure record for entityType={}: entityId length {} exceeds column limit {} (value starts with '{}')",
122+
entityType,
123+
entityId.length(),
124+
ENTITY_ID_MAX_LENGTH,
125+
entityId.substring(0, Math.min(50, entityId.length())));
126+
return;
127+
}
128+
118129
LOG.info(
119130
"Recording {} failure for entityType={}, entityId={}, error={}",
120131
stage,

openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/searchIndex/distributed/PartitionWorker.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323
import java.util.Set;
24+
import java.util.UUID;
2425
import java.util.concurrent.atomic.AtomicBoolean;
2526
import java.util.concurrent.atomic.AtomicLong;
2627
import lombok.extern.slf4j.Slf4j;
@@ -501,8 +502,23 @@ private BatchResult processBatch(
501502

502503
if (failureRecorder != null && readErrorCount > 0) {
503504
for (EntityError entityError : listOrEmpty(resultList.getErrors())) {
504-
String entityId =
505-
entityError.getEntity() != null ? entityError.getEntity().toString() : null;
505+
Object rawEntity = entityError.getEntity();
506+
String entityId = null;
507+
if (rawEntity instanceof EntityInterface) {
508+
UUID id = ((EntityInterface) rawEntity).getId();
509+
if (id != null) {
510+
entityId = id.toString();
511+
}
512+
} else if (rawEntity != null) {
513+
entityId = rawEntity.toString();
514+
}
515+
if (entityId == null) {
516+
LOG.warn(
517+
"Skipping reader failure record for entityType={}: entityId is null, message={}",
518+
entityType,
519+
entityError.getMessage());
520+
continue;
521+
}
506522
failureRecorder.recordReaderEntityFailure(
507523
entityType, entityId, null, entityError.getMessage());
508524
}

openmetadata-service/src/main/java/org/openmetadata/service/socket/Jetty12WebSocketHandler.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.socket.engineio.server.EngineIoWebSocket;
1818
import java.io.IOException;
1919
import java.nio.ByteBuffer;
20+
import java.nio.channels.ClosedChannelException;
2021
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
@@ -128,7 +129,16 @@ public void onClose(int statusCode, String reason) {
128129

129130
@OnWebSocketError
130131
public void onError(Throwable error) {
131-
LOG.error("WebSocket error: {}", error.getMessage(), error);
132-
emit("error", "websocket error", error.getMessage());
132+
if (error instanceof ClosedChannelException) {
133+
LOG.debug("WebSocket channel closed by peer (likely abnormal disconnect)");
134+
return;
135+
}
136+
try {
137+
LOG.error(
138+
"WebSocket error: {} - {}", error.getClass().getSimpleName(), error.getMessage(), error);
139+
emit("error", "websocket error", error.getMessage());
140+
} catch (Exception e) {
141+
LOG.error("Failed to handle WebSocket error gracefully: {}", e.getMessage(), e);
142+
}
133143
}
134144
}

0 commit comments

Comments
 (0)