~netlandish/links-dev

links: Adding DBI transaction rollback when a domain error occurs. This helps prevernt a hanging process due to transaction leak early in the request cycle. v1 APPLIED

Peter Sanchez: 1
 Adding DBI transaction rollback when a domain error occurs. This helps prevernt a hanging process due to transaction leak early in the request cycle.

 3 files changed, 35 insertions(+), 6 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.code.netlandish.com/~netlandish/links-dev/patches/179/mbox | git am -3
Learn more about email & git

[PATCH links] Adding DBI transaction rollback when a domain error occurs. This helps prevernt a hanging process due to transaction leak early in the request cycle. Export this patch

Also gobwebs bump.
---
 domain/middleware.go | 17 +++++++++++++++++
 go.mod               | 12 ++++++------
 go.sum               | 12 ++++++++++++
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/domain/middleware.go b/domain/middleware.go
index efe2e84..e60e915 100644
--- a/domain/middleware.go
+++ b/domain/middleware.go
@@ -2,6 +2,7 @@ package domain

import (
	"context"
	"database/sql"
	"errors"
	"fmt"
	"links/models"
@@ -10,6 +11,7 @@ import (
	"strings"

	"github.com/labstack/echo/v4"
	"netlandish.com/x/gobwebs/database"
	"netlandish.com/x/gobwebs/server"
)

@@ -62,6 +64,21 @@ func DomainContext(service string) echo.MiddlewareFunc {
			req := c.Request()
			domains, err := ValidDomain(req.Context(), req.Host, service, false)
			if err != nil {
				// Log the error for debugging
				gctx := c.(*server.Context)
				gctx.Echo().Logger.Printf(
					"domain.DomainContext: Error validating domain %s: %v\n", req.Host, err)
				
				// Clean up any active transaction before returning error
				// This prevents transaction leaks when domain validation fails
				if dbi := database.DBIForContext(req.Context()); dbi != nil {
					if dbi.HasActiveTransaction() {
						if rbErr := dbi.RollbackTx(); rbErr != nil && rbErr != sql.ErrTxDone {
							gctx.Echo().Logger.Printf(
								"domain.DomainContext: Failed to rollback transaction after validation error: %v", rbErr)
						}
					}
				}
				return err
			}
			if len(domains) != 1 {
diff --git a/go.mod b/go.mod
index 92eaa23..f1f6fb8 100644
--- a/go.mod
+++ b/go.mod
@@ -30,12 +30,12 @@ require (
	golang.org/x/text v0.27.0
	golang.org/x/time v0.8.0
	hg.code.netlandish.com/~netlandish/sendygo v0.0.0-20230124192435-bbf347776232
	netlandish.com/x/gobwebs v0.1.6
	netlandish.com/x/gobwebs-auditlog v0.2.3
	netlandish.com/x/gobwebs-formguard v0.2.4
	netlandish.com/x/gobwebs-graphql v0.2.4
	netlandish.com/x/gobwebs-oauth2 v0.2.3
	netlandish.com/x/gobwebs-ses-feedback v0.2.4
	netlandish.com/x/gobwebs v0.1.7
	netlandish.com/x/gobwebs-auditlog v0.2.4
	netlandish.com/x/gobwebs-formguard v0.2.5
	netlandish.com/x/gobwebs-graphql v0.2.5
	netlandish.com/x/gobwebs-oauth2 v0.2.4
	netlandish.com/x/gobwebs-ses-feedback v0.2.5
	petersanchez.com/x/carrier v0.2.3
	petersanchez.com/x/carrier/ses v0.0.0-20250114214955-7f5d9b835a85
	petersanchez.com/x/carrier/smtp v0.0.0-20250114214955-7f5d9b835a85
diff --git a/go.sum b/go.sum
index ddd92c0..d16509f 100644
--- a/go.sum
+++ b/go.sum
@@ -2580,16 +2580,28 @@ modernc.org/z v1.2.20/go.mod h1:zU9FiF4PbHdOTUxw+IF8j7ArBMRPsHgq10uVPt6xTzo=
modernc.org/zappy v1.0.0/go.mod h1:hHe+oGahLVII/aTTyWK/b53VDHMAGCBYYeZ9sn83HC4=
netlandish.com/x/gobwebs v0.1.6 h1:/fXVU2hoS6FyIk/Refl1FqxCGJxjcCvCybnrxr2JYlI=
netlandish.com/x/gobwebs v0.1.6/go.mod h1:RAf0VNiujzXen/pu0k6yyhvPWMgCY9tKD7ftXrkT53E=
netlandish.com/x/gobwebs v0.1.7 h1:YPqieX9F8lQpjBRq9mrhG4ZKA6SoWMZ0Inz2xu5ZSOM=
netlandish.com/x/gobwebs v0.1.7/go.mod h1:RAf0VNiujzXen/pu0k6yyhvPWMgCY9tKD7ftXrkT53E=
netlandish.com/x/gobwebs-auditlog v0.2.3 h1:U9Kcbacy+6gUbm2wwXUKg4q7RpbRwHgaLXebQWiYlXk=
netlandish.com/x/gobwebs-auditlog v0.2.3/go.mod h1:E5K6BDkD6BTgwGDz2GWOE/h/PfKuyswLDnhU1gDWNPQ=
netlandish.com/x/gobwebs-auditlog v0.2.4 h1:IloSnIc8yGKeEwX5ylKx0I3VoLoa9Bezf98XUnLFIN0=
netlandish.com/x/gobwebs-auditlog v0.2.4/go.mod h1:l1EJbQ79+vWc6l6yFnzRjE4NSRjGTAiwLPxUPQqzy/w=
netlandish.com/x/gobwebs-formguard v0.2.4 h1:YkLudnPrwr9k/giURyohnjlfbuC+Ws8hnrrU+MY8vUc=
netlandish.com/x/gobwebs-formguard v0.2.4/go.mod h1:0UZ/lWNAqHCwDYotp2WlX0XgfsF8PfV8XBr29kSJmP8=
netlandish.com/x/gobwebs-formguard v0.2.5 h1:+Fa5T2qeP2ldv+sIXCVqsLFzp8NXQyI8ZvxVD5TsOA4=
netlandish.com/x/gobwebs-formguard v0.2.5/go.mod h1:Qv+qymuUOCgKzhNmk31DOxT4PLu5bEwXFe2tMEBaljA=
netlandish.com/x/gobwebs-graphql v0.2.4 h1:BWuWiTkTVJNdBITV36r42w7Uh+6HGgZvxOj3+XICsF4=
netlandish.com/x/gobwebs-graphql v0.2.4/go.mod h1:vegE1Sb69L19qk/Urx7HWFhJ3FCjZZ5e0n5PlXDE1Qc=
netlandish.com/x/gobwebs-graphql v0.2.5 h1:h1tr7PP+PbKABD+gP58ldi6GMPRLjAzp6sjXpcozEKg=
netlandish.com/x/gobwebs-graphql v0.2.5/go.mod h1:nNGgCWC098JgaASCsvzZLl1rePzXgGcUtBEB+eJThhg=
netlandish.com/x/gobwebs-oauth2 v0.2.3 h1:gtxVwa/TFquvPm7sL9CYPN6qF9dayovK09bhv8s/bkE=
netlandish.com/x/gobwebs-oauth2 v0.2.3/go.mod h1:OXmkl1iL3MMy4CzdtAc9oOQbX/2kbR8/2t2GCahHBho=
netlandish.com/x/gobwebs-oauth2 v0.2.4 h1:B5V5HNCeRU3TNXK0/59Vnc5Dn7nOA54snxXDnBjn+0g=
netlandish.com/x/gobwebs-oauth2 v0.2.4/go.mod h1:LqCD8OZJkFr8rcDaNYeX8L6tsv/joAQ1k1iriCUlf+E=
netlandish.com/x/gobwebs-ses-feedback v0.2.4 h1:0jSGszEAKxKOJrhiO/vQuuY6lQv7fcsP4s6Iw5EcOJk=
netlandish.com/x/gobwebs-ses-feedback v0.2.4/go.mod h1:s7BCQ4lYPLdvzDuDvZmQn+7IHKsHNIkecs4jcjoZ0ZM=
netlandish.com/x/gobwebs-ses-feedback v0.2.5 h1:o/9aP9CkijohA61834S2AFPk8mN07SkytLvoSAybOeY=
netlandish.com/x/gobwebs-ses-feedback v0.2.5/go.mod h1:Nj7NSW936hRXq2QL1wa95C+g03GLhBIV5MN2K7zorGk=
petersanchez.com/x/carrier v0.2.3 h1:6ScWG2HVFqeqafQp2D9kChNdXYkou4rduzppc3SDYMg=
petersanchez.com/x/carrier v0.2.3/go.mod h1:GLiDI9OThDmruufk/VHlR6Ihvq/hIJQyA5beU6AFNYk=
petersanchez.com/x/carrier/ses v0.0.0-20250114214955-7f5d9b835a85 h1:yy81/rrGdI+YWuTvv7JPvVnY104/g10vnloBnKxVAHk=
-- 
2.49.1
Applied.

To git@git.code.netlandish.com:~netlandish/links
   c877de1..001c767  master -> master