Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Error when closing during a write #145

Open
reconbot opened this issue Aug 19, 2021 · 2 comments
Open

Uncaught Error when closing during a write #145

reconbot opened this issue Aug 19, 2021 · 2 comments

Comments

@reconbot
Copy link
Member

If you shut down the server during a write you'll get an uncaught error. This comes up when using dynalite for testing. I'd expect it to swallow the error or emit it on the server object.

const dynalite = require('dynalite')
const AWS = require('aws-sdk')

/*
Start a write to dyanlite and then shut down the server
*/
async function run() {
  const server = dynalite({ createTableMs: 0 })
  server.on('error', (err) => console.log(`Server Error ${err}`))

  await new Promise(resolve => server.listen(4567, resolve))
  console.log('dynalite started')
  const dynamo = new AWS.DynamoDB({ endpoint: 'http://localhost:4567', region: 'US-EAST-1' })
  await dynamo.createTable({
    TableName: "Music",
    AttributeDefinitions: [
      { AttributeName: "Artist", AttributeType: "S" },
      { AttributeName: "SongTitle", AttributeType: "S" }
    ],
    KeySchema: [
      { AttributeName: "Artist", KeyType: "HASH" },
      { AttributeName: "SongTitle", KeyType: "RANGE" }],
    ProvisionedThroughput: {
      ReadCapacityUnits: 5,
      WriteCapacityUnits: 5
    },
  }).promise()
  console.log('table created')
  const writePromise = dynamo.putItem({
    TableName: "Music",
    Item: {
      "AlbumTitle": { S: "Somewhat Famous" },
      "Artist": { S: "No One You Know" },
      "SongTitle": { S: "Call Me Today" }
     },
  }).promise()
  server.on('connection', () => {
    console.log('closing server')
    server.close()
  })
  writePromise.then(() => console.log('write completed successfully'), () => console.log('write errored as expected'))
}

run().catch(err => console.log(`Run Error ${err}`))

This will error with

★  node dynalite-shutdown.js
dynalite started
table created
closing server

src/node_modules/dynalite/index.js:263
      if (err) throw err
               ^
Error [ReadError]: Database is not open
    at src/node_modules/levelup/lib/levelup.js:190:15
    at src/node_modules/encoding-down/index.js:75:21
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
@reconbot
Copy link
Member Author

It's probably this line that throws the non "statsCode" errors in the http handler. The handler is bound to null so it can't do a this.emit('error', error) instead of throwing. I notice there are a few other locations where there's uncaught throws too, so I'm guessing it was intentional.

Are you open for a change in this behavior?

@mhart
Copy link
Collaborator

mhart commented Aug 19, 2021

Yeah, I think I had it there as a "look, we don't know what this error is, we assume it's bad, let's make sure we crash the process". Definitely overkill if there are known errors that can be dealt with

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

No branches or pull requests

2 participants