Emurgo / cardano-serialization-lib

This is a library, written in Rust, for serialization & deserialization of data structures used in Cardano's Haskell implementation of Alonzo along with useful utility functions.
Other
230 stars 124 forks source link

asmjs TransactionBuilder.min_fee() crash #631

Closed dractw closed 1 year ago

dractw commented 1 year ago

Calling TransactionBuilder.min_fee() few times causing asmjs library to crash until whole asmjs module is reloaded.

Steps to reproduce:

const txBuilder = asm.TransactionBuilder.new(txBuilderConfig)
    const receiver = asm.Address.from_bech32(address)

    txBuilder.add_output(
      asm.TransactionOutput.new(
        receiver,
        asm.Value.new(asm.BigNum.from_str(String(amount))),
      )
    )

    outputs.forEach((out) => {
      this.addUtxoInput(txBuilder, out)
    })

    txBuilder.set_ttl(ttl + defaultTtlOffset)

    if (certs) {
      txBuilder.set_certs(certs)
    }

    return txBuilder.min_fee().to_str()

Execution of code above few times (around 3-5) went OK, but suddenly it throws with Failed to execute 'decode' on 'TextDecoder': the encoded data was not valid. and after that none of asmjs module methods or instances are working until reaload whole module.

Just for example:

image

Can be related: https://github.com/emscripten-core/emscripten/issues/18034

lisicky commented 1 year ago

Hi @dractw ! We are investigating the issue. As workaround you can try to call free() on each CSL object that you don't need. Or use browser version.

dractw commented 1 year ago

@lisicky Hi, i tried your suggestion, unfortunately no luck, it still crashes with Failed to execute 'decode' on 'TextDecoder': the encoded data was not valid. error. Futhermore, i found that crash also happens after calling txBuilder.add_change_if_needed() with undefined error in catch(e)

lisicky commented 1 year ago

@dractw fix on the way. But anyway if you got the error again, you probably didn't free all CSL objects. A CSL object doesn't free resources on GC. This package might help to prevent memory leaks https://www.npmjs.com/package/csl-runtime-gc