{"record":{"id":"7bd38208f3fc4cdb","repo":"apache/flink","slug":"failed-to-serialize-schema-registry-7bd382","errorCode":null,"errorMessage":"Failed to serialize schema registry.","messagePattern":"Failed to serialize schema registry\\.","errorType":"exception","errorClass":"WrappingRuntimeException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/RegistryAvroSerializationSchema.java","lineNumber":125,"sourceCode":"    }\n\n    @Override\n    public byte[] serialize(T object) {\n        checkAvroInitialized();\n\n        if (object == null) {\n            return null;\n        } else {\n            try {\n                ByteArrayOutputStream outputStream = getOutputStream();\n                outputStream.reset();\n                Encoder encoder = getEncoder();\n                schemaCoder.writeSchema(getSchema(), outputStream);\n                getDatumWriter().write(object, encoder);\n                encoder.flush();\n                return outputStream.toByteArray();\n            } catch (IOException e) {\n                throw new WrappingRuntimeException(\"Failed to serialize schema registry.\", e);\n            }\n        }\n    }\n\n    @Override\n    protected void checkAvroInitialized() {\n        super.checkAvroInitialized();\n        if (schemaCoder == null) {\n            schemaCoder = schemaCoderProvider.get();\n        }\n    }\n\n    @Override\n    public boolean equals(Object o) {\n        if (this == o) {\n            return true;\n        }\n        if (o == null || getClass() != o.getClass()) {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/RegistryAvroSerializationSchema.java#L107-L143","documentation":"RegistryAvroSerializationSchema.serialize throws WrappingRuntimeException('Failed to serialize schema registry.') when any IOException occurs while writing the schema id header via schemaCoder.writeSchema() or encoding the record. Unlike the plain AvroSerializationSchema, here this genuinely includes Confluent Schema Registry interactions (e.g. registering/looking up the schema id) failing.","triggerScenarios":"Schema Registry unreachable/timeout, auth (TLS/basic auth) misconfigured, schema registration rejected (incompatible), or the record not conforming to the writer schema — any of these surfaces as this wrapping exception during serialize().","commonSituations":"Network flakiness between TaskManager and the registry; wrong registry URL or missing credentials; schema compatibility mode rejecting a new version; kafka topic + registry mismatch after schema evolution.","solutions":["Unwrap e.getCause(): if it is a RegistryRetrieverException/RetriableException/ConnectException, fix registry connectivity/credentials (URL, basic.auth.credentials.source, TLS truststore).","If registration was rejected, resolve schema compatibility in the registry (evolve the schema compatibly or adjust subject compatibility mode deliberately).","Make the registry client resilient: increase timeouts/retries on the cached schema coder provider; ensure the schema id is pre-registered so writeSchema() only reads.","Verify the record matches getSchema() to rule out a plain encode failure."],"exampleFix":"// before\nRegistryAvroSerializationSchema.forGeneric(topic, false).serialize(record);\n\n// after\n// pre-register the schema once from the client, so the hot path only writes:\nCachedSchemaCoderProvider provider = new CachedSchemaCoderProvider(registryUrl);\n// + fix env: schema.registry.url / basic.auth.user-info set correctly","handlingStrategy":"retry","validationCode":"// fail fast on registry reachability before the job starts\ntry (SchemaRegistryClient c = new CachedSchemaRegistryClient(registryUrl, 100)) {\n    c.getAllSubjects(); // throws if URL/auth wrong\n} catch (IOException e) {\n    throw new IllegalStateException(\"Schema Registry not reachable: \" + registryUrl, e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    bytes = serializer.serialize(record);\n} catch (WrappingRuntimeException e) {\n    Throwable root = ExceptionUtils.stripExecution(e);\n    if (root instanceof RetriableException) {\n        // transient registry hiccup: retry with backoff\n        throw new Retry Later (backoff) exception;\n    }\n    throw e; // schema/data errors are not retriable\n}","preventionTips":["Pre-register schemas from the client so the hot path never writes to the registry.","Configure registry client timeouts/retries and auth in the schema coder provider.","Monitor registry connectivity separately from job health so the cause is obvious."],"tags":["avro","flink","schema-registry","confluent","network","serialization"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}