Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Deadlock calling a function on null #403

Open
cracker0dks opened this issue Dec 18, 2019 · 7 comments
Open

Deadlock calling a function on null #403

cracker0dks opened this issue Dec 18, 2019 · 7 comments

Comments

@cracker0dks
Copy link

Hey, at first I thought this was a node bug and opened an issue there... but they say it probably on DC side... so what do you think?

nodejs/help#2357

cheers

@ralphtheninja
Copy link
Member

What are you trying to do? What should the expected outcome be?

@cracker0dks
Copy link
Author

I was calling a function, but by mistake I called it with "null" so I got the deadlock (No error, nothing). So I traced it back and made a bugreport on the node repo... they say it's not a node problem.

@Jikstra
Copy link
Collaborator

Jikstra commented Dec 22, 2019

Which function? Please post some code/example so we can reproduce this.

@cracker0dks
Copy link
Author

there is not more code than I posted on the nodejs issue:
If have this function:

var test = function (obj) {
    obj.getId();
}

and I call it like this:

dc.on('DC_EVENT_INCOMING_MSG', () => {
    test(null)
})

ofc I didn't called it this way on purpose when I noticed it... :)

@ralphtheninja
Copy link
Member

@cracker0dks It would be really useful if you could post a code snippet that can reproduce the problem, i.e. a minimal example that can be run by e.g. node index.js.

@cracker0dks
Copy link
Author

cracker0dks commented Jan 2, 2020

const DeltaChat = require('deltachat-node');
const dc = new DeltaChat();

var test = function (obj) { 
    obj.getId();
}

dc.on('ALL', function(code, msg, msg1) {
    if(msg1.indexOf("INBOX-fetch started")!==-1) { //Just wait till dc checks the inbox
        console.log("Deltacore locks after this line below <<<")
        test(null)
    }
    console.log("ALL", code, msg, msg1)
})

dc.open(() => {
    const onReady = () => {
        console.log("DeltaChat Core is ready!");
        setInterval(function() {
            console.log("YO!") //Interval to check if node is running (And it is!)
        }, 5000)
    }

    if (!dc.isConfigured()) {
        dc.once('ready', onReady)
        dc.configure({addr:"email",  mail_pw : "password"})
    } else {
        onReady()
    }
});

console.log("START DC!")

Ok, here you go. Paste this into a test.js (change user and pw) and run it. Dc will get a hard locked on "Inbox check". Nodejs will be still running but no more output from dc and no erros

@Jikstra
Copy link
Collaborator

Jikstra commented Jun 23, 2020

const DeltaChat = require('.').default
const dc = new DeltaChat()

const opts = {
  addr: '[email]',
  mail_pw: '[addr]'
}

const contact = '[email2]'

async function main() {
  const dc = new DeltaChat()

  dc.on('ALL', function(code, msg, msg1) {
      throw new Error('test')
      console.log("ALL", code, msg, msg1)
  })

  await dc.open('./')
  
  try {
    await dc.configure(opts)
    console.log('a')
  } catch (err) {
    console.error("Failed to configure because of: ", err)
    dc.close()
    return
  }

  dc.startIO()
  console.log('fully configured')

  dc.stopIO()
  console.log('stopped io')
  dc.close()
}

main()

Seems to look like that weird things happen if we throw an error inside a js method called from the c stuff

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants