WebSocket implementation is buggy or bad documented.

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

@briot đang làm issue này rồi.

Từ ngày 25/6/2020.

  • #159 của @briot — đang mở

Đá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
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Lĩnh vực
backend, networking

Hướng nghiên cứu

Tái hiện vấn đề với aws/demos/websockets dưới trình gỡ lỗi, sau đó lần theo đối tượng tùy chỉnh qua aws-net-websocket-registry.adb, aws-server-http_utils.adb và aws-net.adb. Kiểm tra các đường đi Create và Finalize cũng như lỗi trong aws-net-buffered.adb:147. Công việc được xem là hoàn tất khi vòng đời WebSocket được hỗ trợ được xác lập và ghi lại, đồng thời các Sends phía máy chủ bên ngoài callback được an toàn, kèm một trường hợp hồi quy nếu dự án có vị trí kiểm thử phù hợp.

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

Mô tả

Hello,
I have a problem with Web_Socket API in AWS (server side). The AWS.Net.WebSocket has this:

   function Create
     (Socket  : Socket_Access;
      Request : AWS.Status.Data) return Object'Class
   with Pre => Socket /= null;
   --  Create a new instance of the WebSocket, this is used by AWS internal
   --  server to create a default WebSocket if no other constructor are
   --  provided. It is also needed when deriving from WebSocket.
   --
   --  This function must be registered via AWS.Net.WebSocket.Registry.Register

Looks like to create a custom web socket object one needs to define a function with the same profile and register it with the Register procedure. One (like me) could think that this function will be called to construct a custom web socket when a http client call an URL. AWS indeed calls this, but then it will destroy the object. So if you keep the object to send messages to the client it will raise PROTOCOL_ERRORaws-net-buffered.adb:147 access check failed with traceback like:

#5  0x00007fc950be087f in <__gnat_rcheck_CE_Access_Check> (file=..., line=...) at a-except.adb:1208
#6  0x00007fc951ce0f82 in aws.net.buffered.get_write_cache (socket=..., <get_write_cacheL>=...) at /tmp/openwrt/aws/src/core/aws-net-buffered.adb:147
#7  0x00007fc951ce2dff in aws.net.buffered.write (socket=..., item=...) at /tmp/openwrt/aws/src/core/aws-net-buffered.adb:440
#8  0x00007fc951d3cf34 in aws.net.websocket.protocol.rfc6455.send_frame_header (protocol=..., socket=..., opcd=..., data_length=..., has_mask=..., mask=...) at /tmp/openwrt/aws/src/core/aws-net-websocket-protocol-rfc6455.adb:767
#9  0x00007fc951d3c903 in aws.net.websocket.protocol.rfc6455.send (protocol=..., socket=..., data=..., from_client=...) at /tmp/openwrt/aws/src/core/aws-net-websocket-protocol-rfc6455.adb:626
#10 0x00007fc951da2a62 in aws.net.websocket.send (socket=..., message=..., is_binary=...) at /tmp/openwrt/aws/src/core/aws-net-websocket.adb:597

Property named C is reset by Finalize:

(gdb) bt
#0  aws.net.finalize (socket=...) at /home/max/net/aws/src/core/aws-net.adb:137
#1  0x00007f6a3fd143a6 in web_socket__handlers__aws_handlers__aws_web_socketDF__2 () at /home/max/net/matreshka/source/web/spikedog/aws/web_socket-handlers-aws_handlers.ads:69
#2  0x00007f6a3e7d2a34 in aws.server.http_utils.send (answer=..., http_server=..., line_index=..., c_stat=..., socket_taken=..., will_close=...) at /home/max/net/aws/src/core/aws-server-http_utils.adb:1657
#3  0x00007f6a3e7c2869 in aws.server.http_utils.answer_to_client (http_server=..., line_index=..., c_stat=..., socket_taken=..., will_close=...) at /home/max/net/aws/src/core/aws-server-http_utils.adb:400
#4  0x00007f6a3e7f5fdb in aws.server.protocol_handler (la=...) at /home/max/net/aws/src/core/aws-server-protocol_handler.adb:264
#5  0x00007f6a3e7f2e81 in aws.server.line (<_task>=...) at /home/max/net/aws/src/core/aws-server.adb:327
#6  0x00007f6a3da253f6 in system.tasking.stages.task_wrapper () from /home/max/net/gnat-gpl-2019/lib/gcc/x86_64-pc-linux-gnu/8.3.1/adalib/libgnarl-2019.so

Try to run the example from aws/demos/websockets under debugger. The exampe tries to add its own field C and populate ith with zero:

      return Object'(Net.WebSocket.Object
                       (Net.WebSocket.Create (Socket, Request)) with C => 0);

But when On_Open is called C has a garbage:

(gdb) print Socket.C
$3 = 538976288

(gdb) bt
#0  websock_cb.on_open (socket=..., message=...) at /home/max/net/aws/demos/websockets/websock_cb.adb:118
#1  0x00007ffff77c3d90 in aws.net.websocket.registry.watch (websocket=...) at /home/max/net/aws/src/core/aws-net-websocket-registry.adb:1514
#2  0x00007ffff7772650 in aws.net.websocket.registry.utils.watch (websocket=...) at /home/max/net/aws/src/core/aws-net-websocket-registry-utils.adb:49
#3  0x00007ffff782ce61 in aws.server.http_utils.send (answer=..., http_server=..., line_index=..., c_stat=..., socket_taken=..., will_close=...) at /home/max/net/aws/src/core/aws-server-http_utils.adb:1694
#4  0x00007ffff781c869 in aws.server.http_utils.answer_to_client (http_server=..., line_index=..., c_stat=..., socket_taken=..., will_close=...) at /home/max/net/aws/src/core/aws-server-http_utils.adb:400
#5  0x00007ffff784ffdb in aws.server.protocol_handler (la=...) at /home/max/net/aws/src/core/aws-server-protocol_handler.adb:264
#6  0x00007ffff784ce81 in aws.server.line (<_task>=...) at /home/max/net/aws/src/core/aws-server.adb:327
#7  0x00007ffff6a7f3f6 in system.tasking.stages.task_wrapper () from /home/max/net/aws/demos/websockets/debug/../../../..//gnat-gpl-2019/lib/gcc/x86_64-pc-linux-gnu/8.3.1/adalib/libgnarl-2019.so

Could you suggest how should I create a Web_Socket object to be able to send some message from the server to the client outside of 'On_OpenandOn_Message` callback?

PS Cross-reference to matreshka issue.

Ngôn ngữ chính
Ada
Star
163
Fork
46
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 AdaCore/aws

Tất cả issue của AdaCore/aws

Issue tương tự

Thêm issue về Backend & API Design

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.