Skip to content

Redundant gRPC Python Protobuf Message Descriptor with Bazel + Python 3 #17844

@lidizheng

Description

@lidizheng

This issue is quite challenging to reproduce. Firstly, Bazel doesn't support Python 3, but this buggy behavior only appear in Python 3. Secondly, the gRPC Bazel scripts are wrote for Python 2 only before #17644, which results in installing "enum34" and "concurrent" in Python 3 and generating AttributeErrors. Thirdly, the behavior seems only appear when the client and server both possess a copy of the same proto file, and try to compare them within the same process.

After many failed attempt to minimize the reproduce example, here is a complicate but stable way of reproduce it.

#! /bin/bash -ex

git clone https://github.com/lidizheng/grpc
cd grpc
git co bzl-py3
git revert 222db627212b331381d97468813233738d720e75
bazel test --test_output=errors //src/python/grpcio_tests/tests/reflection/...
bazel test --test_output=errors --config=python3 //src/python/grpcio_tests/tests/reflection/...

The error log will look like:

FAIL: //src/python/grpcio_tests/tests/reflection:_reflection_servicer_test (see /root/.cache/bazel/_bazel_root/d2dc70c3d9da3fab488ba0dcbbd35051/execroot/com_github_grpc_grpc/bazel-out/k8-py3-fastbuild/testlogs/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test/test.log)
INFO: From Testing //src/python/grpcio_tests/tests/reflection:_reflection_servicer_test:
==================== Test output for //src/python/grpcio_tests/tests/reflection:_reflection_servicer_test:
testExtensionNumbersOfType (__main__.ReflectionServicerTest) ... FAIL
testFileByName (__main__.ReflectionServicerTest) ... FAIL
testFileBySymbol (__main__.ReflectionServicerTest) ... FAIL
testFileContainingExtension (__main__.ReflectionServicerTest) ... FAIL
testListServices (__main__.ReflectionServicerTest) ... FAIL
testReflectionServiceName (__main__.ReflectionServicerTest) ... ok
======================================================================
FAIL: testExtensionNumbersOfType (__main__.ReflectionServicerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/.cache/bazel/_bazel_root/d2dc70c3d9da3fab488ba0dcbbd35051/execroot/com_github_grpc_grpc/bazel-out/k8-py3-fastbuild/bin/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.runfiles/com_github_grpc_grpc/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py", line 165, in testExtensionNumbersOfType
    self.assertSequenceEqual(expected_responses, responses)
AssertionError: Sequences differ: (all_[215 chars]ror_response {
  error_code: 5
  error_message: "not found"
}
) != (all_[215 chars]ror_response {
  error_code: 5
  error_message: "not found"
}
)
First differing element 0:
all_e[147 chars]_number: 126
  extension_number: 127
  extension_number: 128
}
all_e[147 chars]_number: 126
  extension_number: 127
  extension_number: 128
}
  (all_extension_numbers_response {
    base_type_name: "grpc.testing.proto2.EmptyWithExtensions"
    extension_number: 124
    extension_number: 125
    extension_number: 126
    extension_number: 127
    extension_number: 128
  }
  ,
   error_response {
    error_code: 5
    error_message: "not found"
  }
  )
======================================================================
FAIL: testFileByName (__main__.ReflectionServicerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/.cache/bazel/_bazel_root/d2dc70c3d9da3fab488ba0dcbbd35051/execroot/com_github_grpc_grpc/bazel-out/k8-py3-fastbuild/bin/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.runfiles/com_github_grpc_grpc/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py", line 87, in testFileByName
    self.assertSequenceEqual(expected_responses, responses)
AssertionError: Sequences differ: (file[143 chars]ror_response {
  error_code: 5
  error_message: "not found"
}
) != (file[143 chars]ror_response {
  error_code: 5
  error_message: "not found"
}
)
First differing element 0:
file_[75 chars]empty.proto\022\014grpc.testing\"\007\n\005Emptyb\006proto3"
}
file_[75 chars]empty.proto\022\014grpc.testing\"\007\n\005Emptyb\006proto3"
}
  (file_descriptor_response {
    file_descriptor_proto: "\n\"src/proto/grpc/testing/empty.proto\022\014grpc.testing\"\007\n\005Emptyb\006proto3"
  }
  ,
   error_response {
    error_code: 5
    error_message: "not found"
  }
  )
======================================================================
FAIL: testFileBySymbol (__main__.ReflectionServicerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/.cache/bazel/_bazel_root/d2dc70c3d9da3fab488ba0dcbbd35051/execroot/com_github_grpc_grpc/bazel-out/k8-py3-fastbuild/bin/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.runfiles/com_github_grpc_grpc/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py", line 111, in testFileBySymbol
    self.assertSequenceEqual(expected_responses, responses)
AssertionError: Sequences differ: (file[143 chars]ror_response {
  error_code: 5
  error_message: "not found"
}
) != (file[143 chars]ror_response {
  error_code: 5
  error_message: "not found"
}
)
First differing element 0:
file_[75 chars]empty.proto\022\014grpc.testing\"\007\n\005Emptyb\006proto3"
}
file_[75 chars]empty.proto\022\014grpc.testing\"\007\n\005Emptyb\006proto3"
}
  (file_descriptor_response {
    file_descriptor_proto: "\n\"src/proto/grpc/testing/empty.proto\022\014grpc.testing\"\007\n\005Emptyb\006proto3"
  }
  ,
   error_response {
    error_code: 5
    error_message: "not found"
  }
  )
======================================================================
FAIL: testFileContainingExtension (__main__.ReflectionServicerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/.cache/bazel/_bazel_root/d2dc70c3d9da3fab488ba0dcbbd35051/execroot/com_github_grpc_grpc/bazel-out/k8-py3-fastbuild/bin/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.runfiles/com_github_grpc_grpc/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py", line 140, in testFileContainingExtension
    self.assertSequenceEqual(expected_responses, responses)
AssertionError: Sequences differ: (file[576 chars]ror_response {
  error_code: 5
  error_message: "not found"
}
) != (file[576 chars]ror_response {
  error_code: 5
  error_message: "not found"
}
)
First differing element 0:
file_[508 chars]pc.testing.proto2.EmptyWithExtensions\030\200\001 \001(\006"
}
file_[508 chars]pc.testing.proto2.EmptyWithExtensions\030\200\001 \001(\006"
}
Diff is 664 characters long. Set self.maxDiff to None to see it.
======================================================================
FAIL: testListServices (__main__.ReflectionServicerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/.cache/bazel/_bazel_root/d2dc70c3d9da3fab488ba0dcbbd35051/execroot/com_github_grpc_grpc/bazel-out/k8-py3-fastbuild/bin/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.runfiles/com_github_grpc_grpc/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py", line 176, in testListServices
    self.assertSequenceEqual(expected_responses, responses)
AssertionError: Sequences differ: (list[209 chars]   name: "Feynman"
  }
  service {
    name: "Galilei"
  }
}
,) != (list[209 chars]   name: "Feynman"
  }
  service {
    name: "Galilei"
  }
}
,)
First differing element 0:
list_[206 chars]
    name: "Feynman"
  }
  service {
    name: "Galilei"
  }
}
list_[206 chars]
    name: "Feynman"
  }
  service {
    name: "Galilei"
  }
}
  (list_services_response {
    service {
      name: "Angstrom"
    }
    service {
      name: "Bohr"
    }
    service {
      name: "Curie"
    }
    service {
      name: "Dyson"
    }
    service {
      name: "Einstein"
    }
    service {
      name: "Feynman"
    }
    service {
      name: "Galilei"
    }
  }
  ,)
----------------------------------------------------------------------
Ran 6 tests in 0.123s

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions