Skip to content

[ATM] Fixed failure when user enters wrong withdraw amount#12

Open
maharshijinandra wants to merge 2 commits into
thesaltree:mainfrom
maharshijinandra:fix_atmFailure01
Open

[ATM] Fixed failure when user enters wrong withdraw amount#12
maharshijinandra wants to merge 2 commits into
thesaltree:mainfrom
maharshijinandra:fix_atmFailure01

Conversation

@maharshijinandra

@maharshijinandra maharshijinandra commented Mar 14, 2026

Copy link
Copy Markdown

When the user enters an invalid withdrawal amount, DispenserAmount() returns an error without releasing the lock, leading to lock contention.
This change fixes the resulting deadlock.

Error output:

ATM state:DispenserAmount
500 note present:1000, 100 not present:1000
 Enter amount to withdraw from atm:
123
fatal error: all goroutines are asleep - deadlock!

goroutine 1 [sync.Mutex.Lock]:
internal/sync.runtime_SemacquireMutex(0x14000078d68?, 0x1c?, 0x102e20268?)
	/opt/homebrew/Cellar/go/1.25.5/libexec/src/runtime/sema.go:95 +0x28
internal/sync.(*Mutex).lockSlow(0x1400010c0e8)
	/opt/homebrew/Cellar/go/1.25.5/libexec/src/internal/sync/mutex.go:149 +0x170
internal/sync.(*Mutex).Lock(...)
	/opt/homebrew/Cellar/go/1.25.5/libexec/src/internal/sync/mutex.go:70
sync.(*Mutex).Lock(...)
	/opt/homebrew/Cellar/go/1.25.5/libexec/src/sync/mutex.go:46
sync.(*RWMutex).Lock(0x1400010c0e8)
	/opt/homebrew/Cellar/go/1.25.5/libexec/src/sync/rwmutex.go:150 +0x6c
atm-machine/atm.(*ATM).CleanPreviousAtmTransaction(0x1400010c000)
	/Users/-/src/low-level-design-golang/atm-machine/atm/atm.go:35 +0x34
atm-machine/atm.(*ATM).Execute(0x1400010c000, 0x1400004e028?)
	/Users/-/src/low-level-design-golang/atm-machine/atm/atm.go:94 +0x3c
main.main()
	/Users/-/src/low-level-design-golang/atm-machine/main.go:46 +0x4a4
exit status 2

cc @thesaltree @codeimmortal

@maharshijinandra maharshijinandra changed the title Fixed failure when user enters wrong withdraw amount [ATM] Fixed failure when user enters wrong withdraw amount Mar 15, 2026
Comment thread atm-machine/atm/atm.go
Remove redundant unlock call in DispenserAmount method.
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.

2 participants