Solvedcore Saving a model using a command does not terminate

I was trying to insert a user to users table and it was successful but the command does not terminate after yield user.save(). I think the iterator is in infinite loop.

Model:

'use strict'

const Lucid = use('Lucid')

class User extends Lucid {

}

module.exports = User

Command:

'use strict'

const Command = use('Command')
const User = use('App/Model/User')

class CreateUser extends Command {

  get signature() {
    return 'createUser {userName}'
  }

  get description() {
    return 'This will create and insert a user to DB'
  }

  * handle(args, options) {

    const user = new User()
    user.username = args.userName
    yield user.save() // Success, but wont terminate after this line
  }
}

module.exports = CreateUser
11 Answers

✔️Accepted Answer

Database connections are long lived connections and you are required to close them manually. For ace commands you can do

const Database = use('Database')

* handle(args, options) {

    const user = new User()
    user.username = args.userName
    yield user.save() // Success, but wont terminate after this line
    Database.close()
  }

Other Answers:

@LordZombi

TL;DR

Mail.connection()._driverInstance.transporter.close()

my troubleshooting steps

  • able to repeat with latest adonis version 4.1
  • then I look for places that has running connections, where I found SMTPPool
  • then I look for places that I can close

underlying source code references

More Issues: