A `MapWidget` built just after another is disposed can lose `mapView#onMapCreated`: the released channel suffix is reused while the old map's async dispose is still in flight

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

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
30/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
dart
Lĩnh vực
mobile

Hướng nghiên cứu

Start in mapbox_maps_platform.dart: _SuffixesRegistry.getSuffix() and _MapboxMapsPlatform.dispose(), where the handler is cleared after the awaited platform#releaseMethodChannels. Check how map_widget.dart takes and returns the suffix in initState and dispose. Reproduce with the fake-channel steps in the issue. Done when a map built after another is disposed still receives mapView#onMapCreated, and the suffix is not reused before its release completes.

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

Mô tả

Versions: mapbox_maps_flutter 3.33.0 (mapbox_maps_flutter_mobile 3.33.0), Flutter 3.47.8. Seen on Android 16 (Galaxy S22); the code involved is the Dart layer both platforms share.

What happens

  1. _MapWidgetState takes its channel suffix when the State is constructed (mapbox_maps_flutter_mobile/lib/src/map_widget.dart:177) and gives it back synchronously in dispose() (:209).
  2. The disposed map's _MapboxMapsPlatform.dispose() is async: it awaits platform#releaseMethodChannels and only then calls _channel.setMethodCallHandler(null) on plugins.flutter.io.<suffix> (mapbox_maps_platform.dart:148-157).
  3. _SuffixesRegistry.getSuffix() hands out suffixesAvailable.first (mapbox_maps_platform.dart:232-245), so a MapWidget whose State is created a frame later gets that same suffix and registers its own handler on the same channel name (map_widget.dart:222, mapbox_maps_platform.dart:22-27).
  4. When the old map's release reply arrives, its setMethodCallHandler(null) clears the new map's handler. The new map's native mapView#onMapCreated reaches nobody: onMapCreated never fires, no MapboxMap is handed out, and the map stays on its defaults (ornaments, camera, nothing drawn) until the app restarts.

A second effect of the same reuse: a mapView#onMapCreated sent to a suffix with no listener is queued by the engine's channel buffers and handed to the next listener of that name, so the next map on that suffix can be "created" by a stale message before its own native view exists; its pigeon calls then fail with channel-error, and its real create is ignored (map_widget.dart:301-304).

The events channel (com.mapbox.maps.flutter.map_events.<suffix>) is not affected — it is cleared synchronously at unmount (map_events.dart:71-72) — so the affected map still reports MapLoaded.

Repro (Dart side, on fakes, no device needed)

Two screens, each holding a MapWidget that is built one frame after its screen mounts (a StatefulWidget that shows SizedBox first and the map from a post-frame setState). Swap them under a keyed parent: A → B → A.

  • B's map is created (send mapView#onMapCreated on its suffix), so it releases on dispose.
  • Hold B's platform#releaseMethodChannels reply.
  • Swap back to A: A's new map takes B's suffix (0, with one map at a time).
  • Complete the held reply, then send mapView#onMapCreated on that suffix: A's onMapCreated is never called.

The same steps with the reply answered before A's map is built pass.

Suggested fixes (any one)

  • Clear the handler in dispose() only if this platform object still owns the channel, or set it to null synchronously before awaiting the release.
  • Release the suffix back to the registry only after platform#releaseMethodChannels completes.
  • Prefer a never-used suffix over a just-released one.

Our workaround, to be removed when this is fixed: the app watches for a map that reports MapLoaded without onMapCreated, or whose first pigeon call fails with channel-error, and rebuilds it under a new key, which takes a fresh suffix.

Ngôn ngữ chính
Dart
Star
382
Fork
205
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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

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 mapbox/mapbox-maps-flutter

Tất cả issue của mapbox/mapbox-maps-flutter

Issue tương tự

Thêm issue về Dart

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.