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

fix: fix a deadlock issue caused by unclosing RUnlock #106

Closed

Conversation

coderi421
Copy link
Contributor

fix: fix a deadlock issue caused by unclosing RUnlock

By the way, there is another alternative, using lambda function, which I didn't commit because it changed the style of the code, if you prefer, I can submit it, as follows:

	for p := range handler.aofChan {
		func() {
			handler.pausingAof.RLock() // prevent other goroutines from pausing aof
			defer handler.pausingAof.RUnlock()

			if p.dbIndex != handler.currentDB {
				// 	select db
				data := reply.MakeMultiBulkReply(utils.ToCmdLine("SELECT", strconv.Itoa(p.dbIndex))).ToBytes()
				_, err := handler.aofFile.Write(data)
				if err != nil {
					logger.Warn(err)
					return // skip this command
				}
				handler.currentDB = p.dbIndex
			}
			data := reply.MakeMultiBulkReply(p.cmdLine).ToBytes()
			_, err := handler.aofFile.Write(data)
			if err != nil {
				logger.Warn(err)
			}
		}()
		handler.aofFinished <- struct{}{}
	}

Limited ability, make it better~

@coderi421 coderi421 closed this Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant