question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

If connection to db lost then deno process die and pup/sub not resuming.

See original GitHub issue

How to handle connection (and other) DB error?


import { connect } from "https://denopkg.com/keroxp/deno-redis/mod.ts"

const redis = await connect({
  hostname: "127.0.0.1",
  port: 6379,
})

const redisSub = await connect({
    hostname: "127.0.0.1",
    port: 6379,
  })

const redisPub = await connect({
    hostname: "127.0.0.1",
    port: 6379,
})



  setInterval(async ()=>{
      console.log(new Date())
      try{
            console.log("==>redis get:",await redis.get("test"))
            await redisPub.publish("test",JSON.stringify({time:new Date()}))
      }catch(err){
          console.log("==>error:",err)
      }   
  },3000)

  var sub = await redisSub.subscribe("test")

  for await (const { channel, message } of sub.receive()) {
    console.log(">>>>>>>>>>>message from redis sub, channel:",channel,", message",message)
  }

Then I kill redis db process on server (emulating of problem with connections) then this app just die…

error: Uncaught Error: Invalid state
  throw new Error("Invalid state");
        ^
    at readLine (https://raw.githubusercontent.com/keroxp/deno-redis/master/io.ts:102:9)
    at async readArrayReply (https://raw.githubusercontent.com/keroxp/deno-redis/master/io.ts:141:16)
    at async RedisSubscriptionImpl.receive (https://raw.githubusercontent.com/keroxp/deno-redis/master/pubsub.ts:64:20)
    at async file:///Users/alex/Documents/Material%20Design%20Web/webserver/test_deno.js:85:39

And if use try/catch, after I restart DB on server, redis.get, pub, sub not resume connection and not working.

  try{
  var sub = await redisSub.subscribe("test")

  for await (const { channel, message } of sub.receive()) {
    console.log(">>>>>>>>>>>message from redis sub, channel:",channel,", message",message)
  }
}catch(err){console.log("==>sub error:",err)}
==>error: BrokenPipe: Broken pipe (os error 32)   
    at unwrapResponse ($deno$/ops/dispatch_minimal.ts:63:11)
    at Object.sendAsyncMinimal ($deno$/ops/dispatch_minimal.ts:106:10)
    at async Object.write ($deno$/ops/io.ts:65:18)
    at async BufWriter.flush (https://deno.land/std@v0.51.0/io/bufio.ts:475:25)
    at async sendCommand (https://raw.githubusercontent.com/keroxp/deno-redis/master/io.ts:62:3)

So how to handle pub/sub error and resume connection and working state?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
sebastienfilioncommented, Jun 22, 2020

@Terkwood that was my idea. I’ve been working on a solution for the past few days; finishing testing. I hope I can push tomorrow for you all to see.

5reactions
sebastienfilioncommented, Jun 16, 2020

As a first step, I created a test to reproduce the issue that @devalexqt reported. If it makes sense, I can look into suggesting a fix. https://github.com/keroxp/deno-redis/pull/92

Read more comments on GitHub >

github_iconTop Results From Across the Web

office_spirit_mysql@0.11.2 | Deno
This process is transparent to you. In the beginning of callback , the conn is not connected to the server. It will connect...
Read more >
bun/README.md at main · oven-sh/bun - GitHub
Traditional file watchers restart the entire process which means that HTTP servers and other stateful objects are lost. bun --hot does not restart...
Read more >
Woe be unto you for using a WebSocket - Hacker News
- As is pointed out in the article, a TCP connection can cease to transmit data even though it has not closed. So...
Read more >
What is Deno and is Node.js Dying? - Morioh
In this video, we will be talking about what is Deno? and Deno vs Node. Is Node.js going to die? so stay tuned...
Read more >
log - nichoth
The problem of encrypting the data is solved using the above method. ... It's not any less decentralized than the current system with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found