iTwin / imodel-transformer

API for exporting an iModel's parts and also importing them into another iModel
MIT License
3 stars 2 forks source link

processSchemas crashes node process with Segmentation Fault #34

Open simsta6 opened 1 year ago

simsta6 commented 1 year ago

Describe the bug proccessSchemas crashes node process with Segmentation Fault while importing dynamic schema from source iModel when target iModel has incompatible version of that same dynamic schema.

It's possible that this bug is also reproducible with different schema importing issues.

To Reproduce

  1. Create two source iModels. Import same name dynamic schemas, but with different versions to them.
  2. Run transformation with the first iModel.
  3. Run transformation with the second iModel.
  4. Node process crashes

Expected behavior It should throw an error

Desktop (please complete the applicable information):

Additional context Add any other context about the problem here.

EC Schemas for test cases:

        <?xml version="1.0" encoding="UTF-8"?>
        <ECSchema schemaName="RevitDynamic" alias="RVT13469" version="01.07.00" displayLabel="Revit" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2">
            <ECCustomAttributes>
                <DynamicSchema xmlns="CoreCustomAttributes.01.00.03"/>
            </ECCustomAttributes>
        </ECSchema>
        <?xml version="1.0" encoding="UTF-8"?>
        <ECSchema schemaName="RevitDynamic" alias="RVT1641" version="01.05.02" displayLabel="Revit" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2">
            <ECCustomAttributes>
                <DynamicSchema xmlns="CoreCustomAttributes.01.00.03"/>
            </ECCustomAttributes>
        </ECSchema>
MichaelBelousov commented 11 months ago

I feel like your description and reproduction steps don't match... Are you saying it crashes "when reusing a single transformer instance on a second source" or "when transforming between any source and target with a same-name dynamic schema"?

MichaelBelousov commented 11 months ago

@simsta6 I have created this test and it does not reproduce. Could you point out where I'm deviating from your description? (the branch is here if you'd like to fork/edit it)

it.only("handle same name dynamic schemas", async function () {
  const makeDynamicSchema = (version: string) => `<?xml version="1.0" encoding="UTF-8"?>
      <ECSchema schemaName="Dynamic" alias="d1" version="${version}" displayLabel="dyn" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2">
          <ECCustomAttributes>
              <DynamicSchema xmlns="CoreCustomAttributes.01.00.03"/>
          </ECCustomAttributes>
      </ECSchema>
  `;

  /* eslint-disable @typescript-eslint/naming-convention */
  const dynamicSchema1_7_0 = makeDynamicSchema("01.07.00");
  const dynamicSchema1_5_2 = makeDynamicSchema("01.05.02");
  /* eslint-enable @typescript-eslint/naming-convention */

  const sourceDbFile: string = IModelTransformerTestUtils.prepareOutputFile("IModelTransformer", "DynSchemas-Source.bim");
  const sourceDb = SnapshotDb.createEmpty(sourceDbFile, { rootSubject: { name: "DynSchemaSource" } });
  await sourceDb.importSchemaStrings([dynamicSchema1_7_0]);
  sourceDb.saveChanges();

  const targetDbFile: string = IModelTransformerTestUtils.prepareOutputFile("IModelTransformer", "DynSchemas-Target.bim");
  const targetDb = SnapshotDb.createEmpty(targetDbFile, { rootSubject: { name: "DynSchemasTarget" } });
  await targetDb.importSchemaStrings([dynamicSchema1_5_2]);
  targetDb.saveChanges();

  const transformer = new IModelTransformer(sourceDb, targetDb);
  // expect this to not reject, adding chai as promised makes the error less readable
  await transformer.processSchemas();

  expect(targetDb.querySchemaVersion("Dynamic")).to.equal("1.7.0");

  // clean up
  transformer.dispose();
  sourceDb.close();
  targetDb.close();
});
MichaelBelousov commented 11 months ago

possibly fixed by https://github.com/iTwin/imodel-native/pull/404

MichaelBelousov commented 10 months ago

will update once iTwin/imodel-native#404 is released in a patch

MichaelBelousov commented 10 months ago

was release as 4.1.1 (iirc). @simsta6 is it possible to test this?

simsta6 commented 10 months ago

@MichaelBelousov it will take some time. I will get back to you when I will test it out