You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Xusheng Zhang (Jira)" <ji...@apache.org> on 2020/05/06 12:41:00 UTC

[jira] [Commented] (THRIFT-4781) C++ clients crash when exceptions are typedefed in the IDL

    [ https://issues.apache.org/jira/browse/THRIFT-4781?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17100765#comment-17100765 ] 

Xusheng Zhang commented on THRIFT-4781:
---------------------------------------

Hi, I'm Xusheng Zhang from China.

I have the exactly the same problems with Andrej Nazarov. I also use VS 2019 on Windows 10 to bulid the thrift 0.13.0 to get cpp library.

1. I also upgraded to target toolset to 'v142' (was 'v100') when prompted (v100 = VS2010).

2. For Boost, OpenSSL, libevent, I directly use the NuGet tool to stall them: boost_vc120, libevent_vc120, openssl_no-asm_vc120.

3. And I get the same complile errors except the sixth one( C1083 : Cannot open include file: 'event2/event-config.h>, I guess because I use the NuGet).

However, according to my own understanding, I solved two kinds of errors.

For error:
|C1083|Cannot open include file: 'thrift/config.h': No such file or directory|libthrift|C:\libs\copy\thrift-0.13.0\lib\cpp\src\thrift\transport\THttpClient.cpp|25|
|C1083|Cannot open include file: 'thrift/config.h': No such file or directory|libthrift|C:\libs\copy\thrift-0.13.0\lib\cpp\src\thrift\transport\THttpServer.cpp|24|

I creat a config.h under the dir : lib/cpp/src/thrift, the content is :

 
{code:java}
#include <stdlib.h>
#include <string.h>
 
#define PACKAGE_VERSION "0.13.0"
{code}
For error:

 
|C2491|'apache::thrift::transport::TSSLSocketFactory::manualOpenSSLInitialization_': definition of dllimport static data member not allowed|libthrift|C:\libs\copy\thrift-0.13.0\lib\cpp\src\thrift\transport\TSSLSocket.cpp|851|

I change the data type of manualOpenSSLInitialization_ as following:

 
{code:java}
//bool TSSLSocketFactory::manualOpenSSLInitialization_ = false;
bool manualOpenSSLInitialization_ = false;
{code}
 

 

In a summary,  the following errors are still bother me:
|C1083|Cannot open source file: 'src\thrift\concurrency\BoostMonitor.cpp': No such file or directory|libthrift|C:\libs\copy\thrift-0.13.0\lib\cpp\c1xx|1|
|C1083|Cannot open source file: 'src\thrift\concurrency\BoostMutex.cpp': No such file or directory|libthrift|C:\libs\copy\thrift-0.13.0\lib\cpp\c1xx|1|
|C1083|Cannot open source file: 'src\thrift\concurrency\BoostThreadFactory.cpp': No such file or directory|libthrift|C:\libs\copy\thrift-0.13.0\lib\cpp\c1xx|1|
|C1083|Cannot open source file: 'src\thrift\concurrency\StdThreadFactory.cpp': No such file or directory|libthrift|C:\libs\copy\thrift-0.13.0\lib\cpp\c1xx|1|
|C1083|Cannot open source file: 'src\thrift\concurrency\Util.cpp': No such file or directory|libthrift|C:\libs\copy\thrift-0.13.0\lib\cpp\c1xx|1|

 

I hope you can make time to solve this problem and thank you very much!

And would you mind sending me the  thrift cpp library as .lib file to my email( [iiint@foxmail.com|mailto:iiint@foxmail.com] ) or give me a link where I can download the cpp library(.lib file) so I can directly use it to continue my work.

Thank you again!

> C++ clients crash when exceptions are typedefed in the IDL
> ----------------------------------------------------------
>
>                 Key: THRIFT-4781
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4781
>             Project: Thrift
>          Issue Type: Bug
>          Components: C++ - Compiler
>    Affects Versions: 0.11.0, 0.12.0
>            Reporter: Andrej Nazarov
>            Priority: Major
>         Attachments: image-2020-05-06-20-15-44-986.png
>
>
> If exceptions are typedefed in the IDL, they're generated as pointers in Cpp. This causes a runtime crash (memory access violation) on the C++ client-side when a server sends that exception and the client tries to read it. Example follows:
> {code:java|title=service.thrift}
> namespace * thrifttest.service
> include "errors.thrift"
> typedef errors.FooError FooError
> service FooBarService
> {
> 	string getFooString(1: i32 stringLength) throws (1: FooError e);
> 	string getBarString(1: i32 stringLength) throws (1: errors.BarError e);
> }
> {code}
> {code:java|title=errors.thrift}
> namespace * thrifttest.errors
> exception FooError {
>   1: string message
> }
> exception BarError {
>   1: string message
> }
> {code}
> {code:java|title=FooBarService.h}
> class FooBarService_getFooString_presult {
>  public:
>   virtual ~FooBarService_getFooString_presult() throw();
>   std::string* success;
>   FooError* e; //note pointer declaration of the exception field
> // snip...
> class FooBarService_getBarString_presult {
>  public:
>   virtual ~FooBarService_getBarString_presult() throw();
>   std::string* success;
>    ::thrifttest::errors::BarError e; //note different declaration of the exception field
> //snip
> {code}
> {code:java|title=FooBarService.cpp}
> uint32_t FooBarService_getFooString_presult::read(::apache::thrift::protocol::TProtocol* iprot) {
> // snip...
>   while (true)
>   {
> // snip...
>     switch (fid)
>     {
> // snip...
>       case 1:
>         if (ftype == ::apache::thrift::protocol::T_STRUCT) {
>           xfer += (*(this->e)).read(iprot); // <-- this line causes access violation crash because the pointer is not initialized
>           this->__isset.e = true;
>        // snip...
> uint32_t FooBarService_getBarString_presult::read(::apache::thrift::protocol::TProtocol* iprot) {
> // snip...
>   while (true)
>   {
> // snip...
>     switch (fid)
>     {
> // snip...
>       case 1:
>         if (ftype == ::apache::thrift::protocol::T_STRUCT) {
>           xfer += this->e.read(iprot); //<-- this gets read OK.
>           this->__isset.e = true;
> //snip
> {code}
> This happens regardless of server language (reproducible if server throwing the exceptions is Java, Python or C++)
>  I guess this logic in [t_cpp_generator.cc:1104|https://github.com/apache/thrift/blob/0.11.0/compiler/cpp/src/thrift/generate/t_cpp_generator.cc#L1104] gets deceived in case of typedefed exceptions:
> {code:java|title=t_cpp_generator.cc}
> (pointers && !(*m_iter)->get_type()->is_xception()),
> {code}
> I'm no Thrift compiler expert, but I assume there is a reason why you don't want exceptions to be declared as pointers. Yet in this case they clearly are.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)