SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Go

Go static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your GO code

  • All rules 94
  • Vulnerability21
  • Bug13
  • Security Hotspot14
  • Code Smell46
Filtered: 1 rule found
database
    Impact
      Clean code attribute
        1. Database transactions should be properly handled with rollback mechanisms

           Bug

        Database transactions should be properly handled with rollback mechanisms

        intentionality - complete
        reliability
        maintainability
        Bug
        • database
        • transaction
        • resource-leak

        This rule raises an issue when a database transaction is started with db.Begin() but lacks proper rollback handling in error scenarios.

        Why is this an issue?

        How can I fix it?

        More Info

        Database transactions follow ACID principles (Atomicity, Consistency, Isolation, Durability) to ensure data integrity. When a transaction is started but not properly handled, several problems can occur:

        Data Integrity Violations: If an error occurs during transaction execution and the transaction is not rolled back, partial changes may remain in the database. This violates the atomicity principle, where either all operations in a transaction should succeed or none should.

        Resource Leaks: Unhandled transactions can hold database locks and connections longer than necessary. This can lead to connection pool exhaustion and performance degradation, especially under high load.

        Inconsistent Application State: When transactions are not properly cleaned up, the application may continue with an assumption that operations succeeded when they actually failed partially. This can lead to data corruption and unpredictable behavior.

        The standard pattern in Go is to use defer tx.Rollback() immediately after successfully creating a transaction. This ensures that if any error occurs before tx.Commit() is called, the transaction will be automatically rolled back. The Rollback() method is safe to call even after a successful commit, making this pattern both safe and reliable.

        What is the potential impact?

        Improper transaction handling can lead to data corruption, resource exhaustion, and application instability. In financial or critical systems, this could result in data loss, inconsistent records, or system downtime.

          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

        © 2025 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use