question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Duplicate type name" error when fetching similar schemas

See original GitHub issue

There is a bug (at least, I think it’s unexpected behaviour) in the avsc library where it mutates the passed forSchemaOptions to add a registry to it, which then means subsequent calls using the same forSchemaOptions then crash with a “Duplicate type name” error. See https://github.com/mtth/avsc/issues/312.

This caused a crash for us because the schema registry reuses the options object between calls. So for example, given schemas 1 and 2 which both contain a record with the same name, the following code will crash:

const reg = new SchemaRegistry(
    { host: 'http://localhost:3322' },
    { forSchemaOptions: {} },
);
await reg.getSchema(1);
await reg.getSchema(2); // Error: duplicate type name

Which is obviously quite a big problem because as soon as we try and parse an old and newer version of a subject, our app crashes with this error.

It’s worth noting that the crash only happens if we specify forSchemaOptions, as otherwise forSchema gets called with undefined and there’s nothing for avsc to mutate.

So primarily I think this is a bug in avsc and I wanted you to be aware – in my opinion it should be perfectly valid for the schema registry to pass the same options into it every time. However it might be worth putting a work around in. For our use case we’re patching this line to always pass an empty registry object in:

this.schemasByRegistryId[registryId] = avro.Type.forSchema(schema, {...this.forSchemaOptions, registry: {}})

so that might be a change worth including for the time being? I’m not sure why avsc even exposes the registry as an option as it feels like an implementation detail to me, so perhaps there’s some use case I’m not aware of.

Thanks very much!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

3reactions
henrymunrocommented, Jun 8, 2022

I’ve also hit this when attempting to pass logicalTypes to the avro options.

Had a go at pushing a PR, making this change locally fixed the issue: https://github.com/kafkajs/confluent-schema-registry/pull/209

0reactions
jcjpcommented, Oct 24, 2022

We are actually experiencing this issue but we don’t use forSchemaOptions property. We are setting up our schemaRegistry:

public registry = new SchemaRegistry({
    auth: { ... },
    host: { ... }
  }, {
    [SchemaType.AVRO]: {registry: typeMap}
  })

We populate the typeMap variable using this:

import avro from 'avsc'

...

for (let subj of refs) {
      if (!typeMap[subject]) {
        ...
        typeMap[subject] = avro.Type.forSchema(schema)
      }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Graphql Schema type error indicating duplicate types, which it ...
Schema has the following errors: - Schema contains duplicate type names. Appears that case is no longer adhered to so we had to...
Read more >
RuntimeError: Duplicate type definition found for name - GitLab
An error occurred while fetching the assigned iteration of the selected issue.
Read more >
ERROR: Duplicate column xxxx" while importing ... - Search
This issue occurs when the "Import Column Name from First Line" option is checked and when there is duplicate data in the first...
Read more >
Error creating record from xml schema - webMethods
If you are using schemas that have 'high-level' contructs that use the same 'base' types, it is possible to get this warning without...
Read more >
Duplicate Definition Error - Redgate forums
I just had this issue using SSC 3.7. Someone reordered the columns in a table and also edited the trigger in the same...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found