Reproduced defects from a REST/datastore bug hunt: delete race, PUT/log 500s, CSV surrogate truncation, query-cache key

Đang mở
#233 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 5 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
12/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
flask, python, sqlite
Lĩnh vực
api, backend, database

Hướng nghiên cứu

This is a bundle of eight separate defects, not one starting point. Begin with the DELETE /api/0/buckets/<id> handler in rest.py and Datastore.delete_bucket in aw-core, where the cached bucket handle is dropped before the storage delete commits. Each item needs its own reproduction and fix, and several touch locking and aw-core, so a maintainer should choose one item to start with. Done means each reproduced case returns the documented status code and has a regression test.

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

Mô tả

These are defects from a bug hunt over aw-server master (0ab73fe). Each one was triggered by a test against the Flask test client or a live werkzeug server. Three others are fixed in #230, #231 and #232. This issue lists the rest so none are lost. Open PRs and issues were checked for overlap.

1. A request during DELETE /api/0/buckets/<id> leaves a zombie bucket that returns 500 until it's re-created

  • Root cause: Datastore.delete_bucket (aw-core) drops its cached Bucket handle before the storage delete commits. A concurrent request (heartbeat or read, each on its own peewee connection) still sees the bucket and re-caches the handle.
  • After the delete returns 200, GET /buckets/ no longer lists the bucket, but GET /buckets/<id>, /events, heartbeat and POST /events all return 500 instead of 404.
  • Trigger: delete a 300k-event bucket (about 0.4 s) while its watcher heartbeats. Deleting a large bucket from the web UI with its watcher running is enough.
  • Two concurrent DELETEs give [200, 500] instead of [200, 404].
  • Fix direction: drop the cached handle after the storage delete (aw-core), and run check_bucket_exists under the write lock for writes.

2. PUT /api/0/buckets/<id> with a partial body returns 500

  • rest.py indexes data["type"], ["client"], ["hostname"] and ["data"] directly, although the update_bucket model marks every field optional.
  • {"hostname": "x"} gives KeyError, and null or [1] give TypeError; all three surface as 500. Draft #201 happens to switch this to .get.

3. GET /api/0/log always returns 500

  • get_log calls json.loads on each line, but the file handler writes human-readable lines.
  • With no log file, it calls open(None).
  • It also returns (payload, 200) inside another (…, 200).

4. CSV export returns 200 and then a truncated body when event data contains a lone UTF-16 surrogate

  • POST /events accepts {"title": "bad\ud83d"}, and JSON export handles it. In /export/csv, werkzeug's UTF-8 encode raises partway through the stream.
  • The client gets IncompleteRead, and every row after that event is silently missing.

5. The query cache key misses inputs that change the result

  • QueryCache.key is the query text plus the UTC-normalized period. Three cases return stale results:
    • ?name= (exposed as NAME): RETURN = NAME; returns the first caller's name to later callers.
    • STARTTIME/ENDTIME keep the client's offset, so RETURN = STARTTIME; for …T02:00:00+02:00 is served to a later request for …T00:00:00Z.
    • A query that reassigns STARTTIME reads outside its period, so writes there don't invalidate it.
  • aw-webui uses none of these patterns today, so this is low impact.

6. Concurrent first get_device_id() calls return an empty or different id

  • api.py does an exists check, then open("w"), then a write, with no lock.
  • Fresh data dir, 8 threads calling GET /info: 185 of 300 trials returned "" to some caller.
  • A !local bucket created then keeps a wrong data.device_id. This only affects first run.

7. Deleting a bucket during GET /api/0/export truncates the export after the 200

  • The bucket list is captured up front, and self.db[bid] is resolved lazily in the generator.
  • A bucket deleted mid-stream raises KeyError and produces an unterminated JSON backup.

8. Finite but overflowing values return 500 instead of 400 (same class as #214)

  • An event with duration: 1e12, or with a timestamp of 9999-12-31T23:59:59Z plus a duration, raises OverflowError in event_range. _parse_event only catches ValueError and TypeError.
  • pulsetime=1e12 passes the #207 isfinite check, then overflows in heartbeat_merge.

Refuted / not filed:

  • Two aw-core findings, the reversed 10-second SQLite commit check and endtime rounded 1 ms past the period end, reproduce only with the aw-core commit aw-server currently pins. Upstream aw-core already fixed both (the second in aw-core#162), and #229 repins it.
  • Out-of-order heartbeat caching is deliberate and matches aw-server-rust.
Ngôn ngữ chính
Python
Star
129
Fork
105
Merge trung bình
4 ngày 23 giờ
Pull request đã merge (30 ngày)
17

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ActivityWatch/aw-server

Tất cả issue của ActivityWatch/aw-server

Issue tương tự

Thêm issue về Python

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.