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.

Does rollback really work?

See original GitHub issue

Knex version: 0.16.3 Database + version: mysql, 5.5 OS: Windows

I am making the inner query fail by adding a wrong column! Inner query fails, but does not rollback whole transaction! Here is my code:

return knex.transaction(function (trx) {
	return trx.insert({...}, 'id').into('dept').then(function (response) { **// passes, but should rollback!**
		return trx.batchInsert('emp', [{...}, {...}], 10); **// wrong query!**
	}).then(function (value) {
		console.log('Inside success:', value);
		// trx.commit();
	}).catch(function (error) {
		console.log('Inside error:', error); **// comes here!**
		// trx.rollback(error);
		throw new Error('Rolling back!');
	});
}).catch((err) => {
	console.log("We get here", err); **// comes here!; still no rollback??**
});

I tried with trx.rollback(); trx.rollback(error) or even throwing Error; with promise return and without promise return. It falls in both error blocks (inner and outer); still surprisingly no rollback!!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:25 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
tariq-tbcommented, Sep 19, 2019

I ran into transaction issues with knex and a legacy MySQL db, which led me to this thread. Cause of the issue was MyISAM was being used instead of InnoDB, so ensure you’re using the latter.

1reaction
elhigucommented, Jan 29, 2019

Cannot reproduce, add complete reproduction code please… something that creates necessary tables and shows that the code above does not work. Check CONTRIBUTING.md why and what minimal reproduction code means.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does rollback really work? · Issue #3017 · knex/knex - GitHub
I am making the inner query fail by adding a wrong column! Inner query fails, but does not rollback whole transaction! Here is...
Read more >
How We Rollback Code Releases In Less Than a Minute
Rollbacks required roughly the same amount of time to complete as a typical deploy (20m). That meant that a bad code release would...
Read more >
Explaining netcode in games, and why rollback is overrated ...
Rollback is excellent for casual play but has significant vulnerabilities in competitive for-money play ; it's not a silver bullet, nor is it...
Read more >
Rollback Netcode Explained - Game Rant
The idea is that rollback makes it so playing the game feels instant regardless of your opponent's connection. At the very least, a...
Read more >
The art of rollback: What is rollback and how does it work?
I will not wait for the last episode to unveil the conclusion of the series: yes, it is possible to design a good...
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