appsmithorg / appsmithorg/appsmith

snapshot: deleteAllByApplicationId and createSnapshots not wrapped in transaction - server crash leaves application with no snapshot

Đang mở Phù hợp với người mới
#42,115 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
40.9k
Fork
4.8k
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
45

Mô tả

## Bug Description

createApplicationSnapshot calls deleteAllByApplicationId to remove all existing snapshot chunks, then calls createSnapshots to write the new ones. There is no transaction wrapping these two operations. If the server crashes or the MongoDB connection drops after the delete completes but before createSnapshots finishes, the application has no valid snapshot at all.

## Affected file

pp/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationSnapshotServiceCEImpl.java, lines 44-50:

`java
.flatMapMany(artifactExchangeJson -> {
return applicationSnapshotRepository
.deleteAllByApplicationId(branchedApplicationId) // (1) old snapshot destroyed
.thenMany(createSnapshots(branchedApplicationId, applicationJson)); // (2) new snapshot written
})
// no .as(transactionalOperator::transactional)
`

A TransactionalOperator bean is configured in MongoConfig.java. The import path at ImportServiceCEImpl.java:552 already uses .as(transactionalOperator::transactional) for its multi-step writes - the snapshot path has no equivalent.

## Failure scenario

1. Developer creates a snapshot before a risky refactor.
2. deleteAllByApplicationId commits - all previous snapshot chunks are gone.
3. Server receives SIGTERM (deploy restart), OOM kill, or MongoDB connection drops mid-write.
4. createSnapshots stops partway through - partial or zero chunks written.
5. Snapshot feature reports success or fails with no clear error, but the application has lost its snapshot entirely.
6. Developer encounters a problem with their refactor and tries to restore - finds no snapshot.

## Fix

Inject TransactionalOperator into ApplicationSnapshotServiceCEImpl (it is already available in the application context) and wrap both operations:

`java
return applicationSnapshotRepository
.deleteAllByApplicationId(branchedApplicationId)
.thenMany(createSnapshots(branchedApplicationId, applicationJson))
.as(transactionalOperator::transactional);
`

## Environment

Appsmith elease branch (2026-08-13), Java/Spring WebFlux, MongoDB.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start in app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationSnapshotServiceCEImpl.java around lines 44-50, then compare ImportServiceCEImpl.java:552 and the TransactionalOperator configuration in MongoConfig.java. Confirm that deletion and snapshot creation are covered by one transaction, so an interrupted write does not leave the application without its previous valid snapshot.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java, mongodb, spring
Lĩnh vực
backend, databases
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
74/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.